Ios UIImagePickerController委托警告-不兼容类型
我正试图链接我的照片库以在UIImageView中显示一幅图像,这将允许我添加过滤器,但当你选择照片并点击“选择”时,应用程序崩溃。下面是我正在使用的代码; -IBActionchooseImage:idsender{Ios UIImagePickerController委托警告-不兼容类型,ios,objective-c,xcode5,appdelegate,photolibrary,Ios,Objective C,Xcode5,Appdelegate,Photolibrary,我正试图链接我的照片库以在UIImageView中显示一幅图像,这将允许我添加过滤器,但当你选择照片并点击“选择”时,应用程序崩溃。下面是我正在使用的代码; -IBActionchooseImage:idsender{ UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.allowsEditing = YES; picker.sour
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
错误在以下行中:
"picker.delegate = self;"
标记为*从不兼容类型“VSViewController const_strong”分配给“id”
如果有人对如何修复它或将要运行的备用代码有建议,我们将不胜感激
请尽量避免使用过于复杂的语言,我对编码还不熟悉,这个问题已经困扰了我一段时间。在您的头文件中,您需要遵守协议 @界面YourViewController:UIViewController 然后需要实现协议选择器
请阅读以下内容以供参考:您的类实际上需要同时符合UIImagePickerControllerDelegate和UINavigationControllerDelegate。这在类声明中完成:
@interface VSViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
/* ... */
@end
原因已经在这里讨论过了:您是否将UIImagePickerController委托包含到了您的.h中?我不这么认为,编码是什么?在VSAppDelegate.h或VSViewController.h下?我尝试了这两种方法,但在中没有“@protocol”either@JMarsh最有可能的意思是@interface,而不是@protocole头文件?头文件是以.h结尾的文件,@David Xu,您需要更新代码。UIImagePickerControllerDelegate也需要符合UINavigationController协议。将在项目中的何处输入?委托或.h或.m文件?我需要向主文件添加任何内容吗?VSViewController是clas吗你写的是什么?你的意思是它就是我在其中编码的吗?我的假设是VSViewController是你创建的一个类,它有一个相应的头文件和实现文件,比如VSViewController.h和VSViewController.m。这对吗?我还根据你给我们的错误以及你的代码片段进行了假设假设您实际上是在VSViewController的类方法中进行编码。