Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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> {
like image 987
sixtyfootersdude Avatar asked Dec 05 '10 21:12

sixtyfootersdude


4 Answers

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

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate>

and then implement the methods from both delegate interfaces.

like image 64
Denis Hennessy Avatar answered Nov 07 '22 06:11

Denis Hennessy


Nope, like this:

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate> {
like image 25
Sam Ritchie Avatar answered Nov 07 '22 05:11

Sam Ritchie


@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate> 
like image 43
Firoze Lafeer Avatar answered Nov 07 '22 06:11

Firoze Lafeer


As simple as that:

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate>
like image 23
Tal Bereznitskey Avatar answered Nov 07 '22 05:11

Tal Bereznitskey