I know I need to write:
[delegate respondsToSelector:@selector(myMethod:)]
But th开发者_如何学Pythone compiler is complaining that respondsToSelector is not a method in the protocol, which is correct, However I have seen many sample code use this, how do you do it?
Your @protocol
needs to implement <NSObject>
, simply update your protocol definition to look like this:
@protocol MyProtocol <NSObject>
Greg Martin has your answer, but here is a quick explanation of why the compiler complains:
The respondsToSelector:
method is part of the NSObject
protocol, so when you try to send that message to your deleate (of type id
), the compiler has no way of knowing that your delegate might be able to handle it.
精彩评论