开发者

How to verify if a delegate responds to a selector?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜