Question about xcode warning method definition 'XXX' not found

时光毁灭记忆、已成空白 提交于 2019-12-08 10:19:50

问题


I have seen something here1 that states that I can remove these errors in xcode 3 by changing a method like -(IBAction) shakeShakeShake to -(IBAction) shakeShakeShake (id) sender

I am using iphone sdk 3.0 and xcode 3.2.1 on snow leopard

My errors are:

Classes/MainViewController.m:156: warning: 'MainViewController' may not respond to '-shakeShakeShake'

/Users/temp/Desktop/src/Count Down Timer (Utility App)/Classes/MainViewController.m:156:0 /Users/temp/Desktop/src/Count Down Timer (Utility App)/Classes/MainViewController.m:156: warning: (Messages without a matching method signature

Classes/MainViewController.m: At top level:

Classes/MainViewController.m:467: warning: incomplete implementation of class 'MainViewController'

Classes/MainViewController.m:467: warning: method definition for '-pickerView:' not found

Classes/MainViewController.m:467: warning: method definition for '-shakeShakeShake:' not found

----- (sorry about the long error msgs, I tried to cut them down by removing compiler and path info) ---

I have tried adding things like

-(void)shakeShakeShake: (id) sender ;

as a prototype to the .h file and to the .m file

- (IBAction) shakeShakeShake: (id) sender {

dimView.alpha = 0.0f ; }

Making these changes will make the warning go away, but when I run my program and execute this function, it will exit to the Springboard with a console message:

[MainViewController shakeShakeShake]: unrecognized selector sent to instance 0x1213a20 2009-12-21 02:19:17.389 Count Down Timer (Utility App)[43704:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[MainViewController shakeShakeShake]: unrecognized selector sent to instance 0x1213a20'

When I change the function back to - (IBAction) shakeShakeShake { (even if I leave the prototype style in with : (id) sender), the program (a simple utility timer) runs fine and gives no errors to the console.

I can't seem to figure out what I'm doing wrong, but I was always taught to remove warnings if possible as they may note problems that only surface later and are hard to find.

Can anyone point me in the right direction here? thanks very much for your patience, I'm still new at this! ;-)

Thanks Piesia

BTW, shakeShakeShake is called here:

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {

if (event.type == UIEventSubtypeMotionShake) { //Your code here [ self shakeShakeShake ] ; } }

---- error msgs follow

Classes/FlipsideViewController.m:401: warning: incomplete implementation of class 'FlipsideViewController' Classes/FlipsideViewController.m:401: warning: method definition for '-pickerView:' not found Classes/FlipsideViewController.m:401: warning: method definition for '-shakeShakeShake' not found


回答1:


It looks like I need to give the sender parameter explicitly as follows in the message call:

//instance method declaration
- (IBAction) shakeShakeShake: (id) sender ;


- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.type == UIEventSubtypeMotionShake) {

// message -- method signature + parameter information
        [ self shakeShakeShake: self ] ;

}
}
// ^-- needed for shake

//instance method definition
- (IBAction) shakeShakeShake: (id) sender {

    // make window clear
    dimView.alpha = 0.0f ;      // always undim screen in shake as a failsafe
}

When I do it like this, the warnings go away and the app seems to work. Thanks for your time. Piesia



来源:https://stackoverflow.com/questions/1938705/question-about-xcode-warning-method-definition-xxx-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!