CoreMotion [ViewController updateReferenceAttitude:] - 为什么无法识别选择器?
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 和 iPhone 5 C 运行 iOS 10.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];
}
我是 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 和 iPhone 5 C 运行 iOS 10.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];
}