sixtyfootersdude
sixtyfootersdude

Reputation: 27221

Objective C: Multiple delegates

I am curious if and how to make a Controller be the delegate for two different objects.

Is this allowed or is this like multiple inheritance in Java?

Suppose I wanted to have one controller that responded to: <UIAccelerometerDelegate> and <CLLocationManagerDelegate>

Would the header file look like this?

@interface MainViewController : UIViewController <UIAccelerometerDelegate> AND <CLLocationManagerDelegate> {

Upvotes: 15

Views: 11811

Answers (4)

Firoze Lafeer
Firoze Lafeer

Reputation: 17143

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate> 

Upvotes: 5

Denis Hennessy
Denis Hennessy

Reputation: 7463

Actually, it works quite well. Declare your interface like this:

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate>

and then implement the methods from both delegate interfaces.

Upvotes: 43

Sam Ritchie
Sam Ritchie

Reputation: 11038

Nope, like this:

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate> {

Upvotes: 6

Tal Bereznitskey
Tal Bereznitskey

Reputation: 2051

As simple as that:

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate>

Upvotes: 4

Related Questions