如何修复警告
在我的 iPhone 项目中,我收到“找不到方法名称”、“找到多个名为“method_name”的方法”警告消息。
// in TestFirst.h
-(void) testMethod:(int)a;
// in TestFirst.m
TestSecond *ts = [[TestSecond alloc] init];
ts.delegate = self;
// in TestSecond.h
id delegate;
// in TestSecond.m
[delegate testMethod: 5]; // Warning: method name not found
如何解决此类警告?
In my iPhone project, I am getting "method name not found", "multiple methods named 'method_name' found" warning message.
// in TestFirst.h
-(void) testMethod:(int)a;
// in TestFirst.m
TestSecond *ts = [[TestSecond alloc] init];
ts.delegate = self;
// in TestSecond.h
id delegate;
// in TestSecond.m
[delegate testMethod: 5]; // Warning: method name not found
How to resolve this kind of warnings ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以为委托提供精确的类型:
或者您可以创建一个协议:
或者您可以保留动态类型并导入正确的标头:
You can give a precise type for the delegate:
Or you can create a protocol:
Or you can keep the dynamic typing and import the correct headers:
这可能不是最好的方法,但我见过大多数人使用以下模式使用委托:
您可以使用 PerformSelector:withObject: 添加参数,还有一些方法允许您在其他线程中执行选择器。
声明您的委托,则不会有任何错误
如果您像或那样
It might not being the best way to do it but i've seen most people using delegates using the following pattern :
You can add arguments using performSelector:withObject: and there are also methods allowing you to perform the selector in other threads.
You won't have any errors if you declare your delegate like
or