目标C:多名代表 [英] Objective C: Multiple delegates
本文介绍了目标C:多名代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是允许的还是Java中的多重继承?假设我想有一个控制器响应:< UIAccelerometerDelegate>
和 < CLLocationManagerDelegate>
头文件会是这样吗?
@interface MainViewController:UIViewController< UIAccelerometerDelegate> AND< CLLocationManagerDelegate> {
解决方案
实际上,它工作得很好。声明你的界面如下:
@interface MainViewController:UIViewController< UIAccelerometerDelegate,CLLocationManagerDelegate>
然后从两个委托界面实现方法。
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> {
解决方案
Actually, it works quite well. Declare your interface like this:
@interface MainViewController : UIViewController <UIAccelerometerDelegate, CLLocationManagerDelegate>
and then implement the methods from both delegate interfaces.
这篇关于目标C:多名代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文