2017-08-10 63 views
0

我是CoreMotion的新用户。我的第一个程序显示了俯仰,滚转和偏航,但崩溃deviceManager变化值,当它试图设置referenceAttitudeCoreMotion [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不被识别?

回答

0

问题已修复,与CoreMotion无关。该方法

- (void)updateReferenceAttitude 

应该

- (void)updateReferenceAttitude:(UIButton *(sender 

我列入了UIButton重置,而应用程序正在运行,但被后ViewDidLoad启动自动调用同样的方法参考位置。

该问题已通过使用初始引用而不是调用方法的语句来解决。

if (self.refAttitude == nil) 
    { 
     self.refAttitude = self.manager.deviceMotion.attitude; // initial run 
     //  [self updateReferenceAttitude]; 
    } 
相关问题