ios – 从不兼容类型’ViewController * const__strong’分配给’id’

ios – 从不兼容类型’ViewController * const__strong’分配给’id’,第1张

概述我的应用程序中有一个 ImagePickerController. 它效果很好,但除了ipc.delegate = self之外;出现错误消息: Assigning to ‘id’ from incompatible type ‘ViewController *const__strong’ 该应用程序运行良好,所以我忽略了错误消息,但我想我需要知道原因.为什么会出现错误消息? ipc = [[UI 我的应用程序中有一个 ImagePickerController.
它效果很好,但除了ipc.delegate = self之外;出现错误消息:

Assigning to
‘ID’
from incompatible type ‘VIEwController *const__strong’

该应用程序运行良好,所以我忽略了错误消息,但我想我需要知道原因.为什么会出现错误消息?

ipc = [[UIImagePickerController alloc]init];            ipc.modalPresentationStyle = UIModalPresentationCurrentContext;            ipc.delegate = self;            ipc.sourceType = UIImagePickerControllerSourceTypePhotolibrary;            [ipc setAllowsEditing:NO];            [self presentVIEwController:ipc animated:NO completion:nil];
解决方法 如果你看一下UIImagePickerController委托属性的定义,你会看到它被定义为:
@property(nonatomic,assign) ID<UINavigationControllerDelegate,UIImagePickerControllerDelegate> delegate

您设置为委托的任何对象(在这种情况下,您使用self)必须符合UINavigationControllerDelegate协议和UIImagePickerControllerDelegate协议.如果对象不符合这两个协议,您将收到编译时警告.

以下是您声明您的类符合协议的方式:

@interface MyVIEwController : UIVIEwController <UINavigationControllerDelegate,UIImagePickerControllerDelegate>

阅读working with protocols,UINavigationControllerDelegate和UIImagePickerControllerDelegate.

总结

以上是内存溢出为你收集整理的ios – 从不兼容类型’ViewController * const__strong’分配给’id’全部内容,希望文章能够帮你解决ios – 从不兼容类型’ViewController * const__strong’分配给’id’所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1098521.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存