![](/img/trans.png)
[英]Why is this CMDeviceMotionHandler never called by CoreMotion?
[英]CoreMotion [ViewController updateReferenceAttitude:] - why is the selector not recognised?
我是CoreMotion
。 我的第一個程序顯示deviceManager
更改俯仰,滾動和偏航的值,但是在嘗試設置referenceAttitude
時崩潰
- (void)updateReferenceAttitude
{
self.refAttitude = self.manager.deviceMotion.attitude;
NSLog(@"you clicked a button that took a 3D snapshot");
}
在調試中,我方法中的語句
[myButton addTarget:self action:@selector(updateReferenceAttitude:) forControlEvents:UIControlEventTouchUpInside];
崩潰與以下
'NSInvalidArgumentException', reason: '-[ViewController updateReferenceAttitude:]: unrecognized selector sent to instance 0x14875a00'
為了進行測試,我將Xcode 8.3.3與運行iOS 10.3.3的iPhone 5 C配合使用。
誰能解釋為什么無法識別此selector
?
該問題已解決,與CoreMotion
。 方法
- (void)updateReferenceAttitude
應該
- (void)updateReferenceAttitude:(UIButton *(sender
我已經包含了一個UIButton
來在應用程序運行時重置參考姿勢,但是在ViewDidLoad
啟動后ViewDidLoad
自動調用相同的方法。
通過使用語句作為初始引用而不是調用方法,解決了該問題。
if (self.refAttitude == nil)
{
self.refAttitude = self.manager.deviceMotion.attitude; // initial run
// [self updateReferenceAttitude];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.