2010-07-27 38 views
1

我有这个在我的视图控制器:方法在协议没有发现:目标C

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

,给了我这样的警告:

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

但在我的AppDelegate我已经在声明的方法头...

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

由于

回答

5
[[UIApplication sharedApplication] delegate] 

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

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