CoreMotion [ViewController updateReferenceAttitude:] - 为什么选择器不被识别?
问题描述:
我是CoreMotion
的新用户。我的第一个程序显示了俯仰,滚转和偏航,但崩溃deviceManager
变化值,当它试图设置referenceAttitude
CoreMotion [ViewController updateReferenceAttitude:] - 为什么选择器不被识别?
- (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'
为了测试它,我使用运行iOS 10.3.3的iPhone 5 C的Xcode 8.3.3。
任何人都可以解释为什么这selector
不被识别?
答
问题已修复,与CoreMotion
无关。该方法
- (void)updateReferenceAttitude
应该
- (void)updateReferenceAttitude:(UIButton *(sender
我列入了UIButton
重置,而应用程序正在运行,但被后ViewDidLoad
启动自动调用同样的方法参考位置。
该问题已通过使用初始引用而不是调用方法的语句来解决。
if (self.refAttitude == nil)
{
self.refAttitude = self.manager.deviceMotion.attitude; // initial run
// [self updateReferenceAttitude];
}