开发者

Calling Method in xCode

开发者 https://www.devze.com 2023-01-04 08:01 出处:网络
When calling a method, I use [self methodna开发者_运维问答me]; The problem I\'m having is, in xCode I get loads of warnings! It\'s saying \"*xxxappdelegate.app may not respond to methodname*\".

When calling a method, I use

[self methodna开发者_运维问答me];

The problem I'm having is, in xCode I get loads of warnings! It's saying "*xxxappdelegate.app may not respond to methodname*".

Is there a better way to call methods?


If you get that warning, that means either:

  • That method does not exist in your class
  • If you are calling that method on a different class (not self) then you have not imported the headers for that class


These warnings just mean that the compiler does not know if the class in question has the method you are calling. Make sure the method you're calling is defined above the place in the .m file you are using it in, or declare the method at the top of the file.

@implemention A

-(void)blah
{
    [self foo]; // warning!
}

-(void)foo
{
    [self blah]; // no warning
}

@end


There is something called compiling order. When you call method foo it is not defined yet, however when you call method blah it is defined just in the upper line.

Much more specific:

cout << a;
string a = "hello";

When you do that you will get an error undefined variable "a". What you should do is:

string a = "hello";
cout << a;


Add methodname to the @interface for the class, xxxappdelegate in your example. Or just make sure the methodname implementation is before the place you call it in the file.


If the .h file has the method declared there can be some issue related to xcodes inability to index to solve this go to preferences and delete archives and other stored data.

0

精彩评论

暂无评论...
验证码 换一张
取 消