子类化后委托? [英] Delegate after subclassing?

查看:125
本文介绍了子类化后委托?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我无法为标题制定一个简短的问题..

如果我是一个类的子类使用委托协议和属性,我的委托仍然需要实现超类的委托协议,还是我必须为子类定义一个新的委托协议?

In case i subclass a class with a delegate protocol and property, does my delegate still need to implement the delegate protocol of the superclass, or do i have to define a new one for the subclass?

在我的情况下,我的子类 UIImagePickerController

In my case I subclassed UIImagePickerController:

[(UIImagePickerController *)self.myUIImagePickerControllerSubclassInstance setDelegate:self];

当我尝试将其委​​托设置为 self ,从某些视图控制器我收到以下警告:

When I try to set its delegate to self, from some view controller I get the following warning:


警告:语义问题:将'ViewController *'发送到$ b $的参数b不兼容类型
'id'

warning: Semantic Issue: Sending 'ViewController *' to parameter of incompatible type 'id'


推荐答案

您的代表需要遵守 UIImagePickerController 属性声明:

Your delegate needs to comply with UIImagePickerController property declaration:

@property(非原子,赋值)id< UINavigationControllerDelegate,UIImagePickerControllerDelegate>委托

因此,尝试将< UIImagePickerControllerDelegate> 添加到您的子类接口:

So, try adding <UIImagePickerControllerDelegate> to your subclass interface:

@interface YourPicker : UIImagePickerController <UIImagePickerControllerDelegate>
...
@end

可能你需要 UINavigationControllerDelegate 并实施强制方法(如果有的话)。

And probably you'll need UINavigationControllerDelegate and implement mandatory methods, if any.

这篇关于子类化后委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆