开发者

Specifics of implementing custom delegate methods

I want to use my own delegate methods. i follow the tutorial .but is it must to use the class in which i have declared delegate method(protocol definition) for calling that delegate method?cant i call without creating the object for the class in which i ha开发者_运维技巧ve protocol definition? what is the use of the method "delegate respondsToSelector:@selector"…?any help pls.?


what is the use of the method "delegate respondsToSelector:@selector"…?

In objective-c you can send any message to any object, BUT if object can't respond to it then your program may crash - so if you're not sure if certain object responds to some selector then you can (and should) check that in run-time using respondsToSelector: method - it can save you from a lot of troubles.

You don't have to declare protocols as well but they are a good way to make sure that objects of some type respond to selector in compile-time.


Also see Apple's Communicating with Objects, which discusses delegates, protocols, and selectors. Though its listed under Mac OS X, most (if not all) appears to apply to iOS also.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜