This is a very interesting error message, you may want to look at the order of the method you are calling, and the code that causes the warning message.
-(void) aMainMethod{
[self testMethod] //call the method, warning occurs here
....
}
//here's the method you are calling
-(void) testMethod{
NSLog(@"test");
}
If your method is at somewhere after the code you call it (if it’s like above), move it so that it’s before the code (like the code below), and the warning should go away. Even with the warning, you should still be able to compile and run without any problem.
//here's the method you are calling
-(void) testMethod{
NSLog(@"test");
}
-(void) aMainMethod{
[self testMethod] //no warning
....
}
Here’s an article about this with more details.
Hello!
Very Interesting post! Thank you for such interesting resource!
PS: Sorry for my bad english, I’v just started to learn this language
See you!
Your, Raiul Baztepo
Glad I can help ^__^
Cheers
Emily
Thanks a lot! Really helpful, I finally got rid of those silly warnings
If you would have declared the function in the header of the file (the .h file) then it would not matter where the function body exists.
Doing that will fix the errors as well. (Also the programming standard to declaring functions in C and Objective-C).
Well, that would make your interface unnecessarily bloated. You wouldn’t want to add internal methods to your interface.
Thx Ben
Just to declare function in the header resolve the warning. Don’t have to change declaration order necessary.
Thanks, this helped.
FWIW, the problem appears to exist at the file level as well: class #0 in the file order calling a ‘-method’ from class #1 in the file order caused this problem for me. Reordering the files fixed it.
thank you!
my third day in objectiveC.
its annoying structure and too big file size.
they need actionscript for iphone. its better 1million times.
@peter, that was sarcasm, right?
unfortunately, after 2 years working in a flex/AIR team I fear it wasn’t sarcasm but deadly serious, because I know other flex developers would share your view.
imo actionscript isn’t bad, it just has one huuuuuuuge huge disadvantage you’ve overlooked: Flash!!!
that’s why it’s not on the iphone and rightly so. how beautiful it is to be protected against one of the most bloated, outdated, slow and buggy technologies still hanging around. developer community did a good job to bury IE6, we should similarly be looking to bury Flash, not sing it’s praises just out of principle. This is not 1998 anymore but 2010 and Flash is waaaaaay past it’s sell by date!
You speak true my friend, I’m in the Flash business for almost a decade now (8 yrs) so, I’m no Apple fan boy (as some fellow developers would judge) but I agree, Flash it’s way past it’s sell date, we need to move on, explore new technologies. The truth is, right now the only thing that keeps Flash for being bury it’s that there is no other real alternative, unfortunately.
[...] http://mosisa.wordpress.com/2009/02/17/objective-c-warning-class-may-not-respond-to-method/ en http://stackoverflow.com/questions/1064082/myobject-may-not-respond-to-message-foo-noob-objective-c-question [...]
Seems like you are a true professional. Did ya study about the subject? haha
Thank you Emily for pointing out the obvious that is not always so obvious to non C users like me.
Once I placed the function ahead of the code that uses it, the warning went away.
Makes perfect sense…the order does matter, even though the code will compile and run with the warning.
But sometimes we forget
Glad I can help, it confused me for a while as well
Hi Emily,
really interesting. It makes sence since it is also not possible to invoke functions in scripting languages, which are declared after their call.
regards
Ren´e
[...] 最後反覆的思考與問google大神, 發現大家都遇到同樣的問題, 這篇有寫道該如何解決這個問題: http://mosisa.wordpress.com/2009/02/17/objective-c-warning-class-may-not-respond-to-method/ [...]
Thanks for the information. The warning sounds scared, but the solution was very simply.
dm
Why wouldn’t just the Apple guys get themselves Visual Studio and copy it???
thanks for info , it helped a lot
Thanks a lot! I was going crazy about this warning.
This should be obvious, except for people starting to learn Objective-C (like me). I used to program in C but I have been programming in Java only for the last 5 or 6 years, so the notion of order of declaration being important seems strange now.
Thank you for your information!!! Great!!!!
this is very helpful.
saves me a lot of time
thank you