HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 从不兼容类型’ViewController * const__strong’分配给’id’大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序中有一个 ImagePickerController.
效果很好,但除了ipc.delegate = self之外;出现错误消息:

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

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,UINavigationControllerDelegateUIImagePickerControllerDelegate.

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。