views:

45

answers:

1

hi, 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 have protocol definition? what is the use of the method "delegate respondsToSelector:@selector"…?any help pls.?

+1  A: 

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.

Vladimir
That's truth, I have also an explanation on simple protocol usage here http://stackoverflow.com/questions/3322562/what-is-the-best-way-for-a-view-added-via-presentmodalviewcontroller-to-communica/3323043#3323043
iPhoneDevProf