开发者

Objective C: Multiple delegates

开发者 https://www.devze.com 2023-01-28 19:38 出处:网络
I am curious if and how to make a Controller be the delegate for two differen开发者_Go百科t objects.

I am curious if and how to make a Controller be the delegate for two differen开发者_Go百科t 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> {


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

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate>

and then implement the methods from both delegate interfaces.


Nope, like this:

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate> {


@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate> 


As simple as that:

@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号