【发布时间】:2011-06-05 09:44:30
【问题描述】:
这是我第一次在 Objective-C 中使用协议,我遇到了麻烦:这就是我所拥有的:
我有一个 ReportsReceiver.h:
@protocol ReportsReceiver
-(void)receiveData:(NSArray *)theData;
@end
我有一个 MyController.h:
@interface MyController : UIViewController<ReportsReceiver,UITableViewDelegate,UITableViewDataSource> {
}
@end
我有一个带有已实现方法的 MyController.m:
- (void)receiveData:(NSArray *)theData {
NSLog(@"received some data!");
}
然后我有一个带有声明的类 AllUtilities.m:
Protocol *receiverProtocol;
AllUtilities.m 还包含一个初始化协议的方法:
- (void)initProtocol {
receiverProtocol = @protocol(ReportsReceiver);
}
然后在 AllUtilities.m 中我拨打电话:
[receiverProtocol receiveData:anArray];
哪个应用程序因错误而崩溃:
2011-01-07 11:46:27.503 TestGA[91156:207] *** NSInvocation: warning: object 0x9c28c of class 'Protocol' does not implement methodSignatureForSelector: -- trouble ahead
2011-01-07 11:46:27.504 TestGA[91156:207] *** NSInvocation: warning: object 0x9c28c of class 'Protocol' does not implement doesNotRecognizeSelector: -- abort
我该如何解决这个问题?谢谢!!
【问题讨论】:
标签: iphone ios methods protocols