Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C double Delegate protocol

I get the following error when compiling my app.

warning: class 'ConfigureViewController' does not implement the 'MPMediaPickerControllerDelegate' protocol

I know that it means I have to implement the delegate in the Controller. i.e @interface ConfigureViewController : UIViewController <MPMediaPickerControllerDelegate>

However, my current controller already has a delegate implementation for <UITextFieldDelegate> i.e @interface ConfigureViewController : UIViewController <UITextFieldDelegate>

How do I go around this issue?

Thanks, Tee

like image 833
teepusink Avatar asked Nov 03 '09 01:11

teepusink


People also ask

What does @protocol mean in Objective-C?

Objective-C allows you to define protocols, which declare the methods expected to be used for a particular situation. This chapter describes the syntax to define a formal protocol, and explains how to mark a class interface as conforming to a protocol, which means that the class must implement the required methods.

What is Objective-C delegate?

An Objective-C delegate is an object that has been assigned to the delegate property another object. To create one, you define a class that implements the delegate methods you're interested in, and mark that class as implementing the delegate protocol.

What is delegate protocol in IOS?

Delegates are a use of the language feature of protocols. The delegation design pattern is a way of designing your code to use protocols where necessary. In the Cocoa frameworks, the delegate design pattern is used to specify an instance of a class which conforms to a particular protocol.


2 Answers

Just separate them by a comma: <MPMediaPickerControllerDelegate, UITextFieldDelegate>

like image 138
Greg Martin Avatar answered Oct 16 '22 06:10

Greg Martin


One can implement multiple protocols by specifying multiple protocols in the class declaration.

In this case, in order to implement both MPMediaPickerControllerDelegate and UITextFieldDelegate, the class declaration would be:

@interface ConfigureViewController : UIViewController < UITextFieldDelegate, MPMediaPickerControllerDelegate >
like image 22
coobird Avatar answered Oct 16 '22 05:10

coobird