方案中未找到的方法:目标C.

时间:2010-07-27 15:37:58

标签: objective-c protocols

我在视图控制器中有这个:

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

这给了我这个警告:

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

但在我的AppDelegate中,我在标题中声明了方法...

我应该补充说调用有效,只是想摆脱警告。

由于

1 个答案:

答案 0 :(得分:5)

[[UIApplication sharedApplication] delegate]

返回实现UIApplicationDelegate协议的对象。该协议没有方法sendMessageAsSingleObject。所以你的编译器不知道这个方法实际上存在。您需要首先将委托强制转换为应用程序委托的特定类。

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