开发者

Method not found in protocol: Objective C

开发者 https://www.devze.com 2023-01-08 21:17 出处:网络
I have this in my view controller: [[[UIApplication sharedApplication] delegate] sendMessageAsSingleObject:[sender currentTitle]];

I have this in my view controller:

[[[UIApplication sharedApplication] delegate] sendMessageAsSingleObject:[sender currentTitle]];

Which gives me this warning:

warning: '-sendMessageAsSingleObject:' not found in protocol(s)

But in my AppDelegate i have the method declared in the head开发者_JAVA百科er...

I should add that the call works, just want to get rid of the warnings.

Thanks


[[UIApplication sharedApplication] delegate]

Returns an object that implements the UIApplicationDelegate protocol. This protocol doesn't have the method sendMessageAsSingleObject. So your compiler doesn't know that this method is actually there. You need to cast the delegate first to the specific class of your application delegate.

MyAppDelegate *appDelegate = (MyAppDelegate*)[[UIApplication sharedApplication] delegate];
[appDelegate sendMessageAsSingleObject:[sender currentTitle]];
0

精彩评论

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