While you have already accepted the answer, there is more to this problem than there.
UIAlertViewDelegate
is a protocol that implements the delegate design template. You may need to officially inform the runtime environment that you comply with any given protocol (especially if it does not have the necessary methods), but it depends on the design of the class that the protocol declares. You accept the protocol in your class by putting the protocol name in <> when declaring the class, for example:
@interface MyClass : NSObject <delegateProtocolName>
Because many delegated protocol methods are optional, they often check to see if the accepted class implements a particular method as follows:
if ([self.delegate respondsToSelector:@selector(delegatedMethod:)]) {
In this case, you do not need to match the protocol in your header file because it checks to see if a specific delegation method has been implemented.
However, the test can be written in the same way (especially if you need to refer to several required methods / properties in the same function):
if ([self.delegate conformsToProtocol:@protocol(delegateProtocolName)]) {
In this case, you must comply with the protocol in your header file or not pass the test.
To quote the documentation for conformsToProtocol
(taken from Objective-C programming language and emphasis added by me):
This method only matches based on a formal declaration in the header files , as shown above. He does not check to see if the methods declared in the protocol are really the responsibility of the programmers.
source share