Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c iOS摄像头打开时发出警告_Objective C_Ios - Fatal编程技术网

Objective c iOS摄像头打开时发出警告

Objective c iOS摄像头打开时发出警告,objective-c,ios,Objective C,Ios,我刚刚开始iOS开发,所以在我的第一个项目中,我正在开发一个简单的iOS应用程序来拍摄照片并将其显示在屏幕上 这是我的代码,在第四行我得到了错误: - (IBAction)takePicture:(id)sender { UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.sourceType = UIImagePickerControllerSou

我刚刚开始iOS开发,所以在我的第一个项目中,我正在开发一个简单的iOS应用程序来拍摄照片并将其显示在屏幕上

这是我的代码,在第四行我得到了错误:

- (IBAction)takePicture:(id)sender {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType =  UIImagePickerControllerSourceTypeCamera;
    imagePicker.delegate = self;
    [self presentModalViewController:imagePicker animated:YES];
}
我得到以下警告:

  Assigning to 'id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>' from incompatible type 'todd_learningViewController *const __strong'
从不兼容的类型“todd_learningViewController*const”分配给“id”
我不明白警告信息,也不知道如何摆脱警告

谢谢

编辑:

我的类头文件如下所示:

  @interface todd_learningViewController : UIViewController <UIApplicationDelegate>

  - (IBAction)takePicture:(id)sender;

  @property (weak, nonatomic) IBOutlet UIImageView *pictureView;

  @end
@接口todd\u learningViewController:UIViewController
-(iAction)拍照:(id)发送者;
@属性(弱、非原子)IBUIImageView*pictureView;
@结束

我应该如何修改它?

首先在课堂上实现下面的委托

<UIPickerViewDelegate,UIPickerViewDataSource>

@interface className : NSObject <UIApplicationDelegate,UIPickerViewDelegate,UIPickerViewDataSource> {


}

@接口类名:NSObject{
}
应该是这样的

@interface todd_learningViewController : UIViewController <UIApplicationDelegate,UIPickerViewDelegate,UIPickerViewDataSource>{

    }

  - (IBAction)takePicture:(id)sender;

  @property (weak, nonatomic) IBOutlet UIImageView *pictureView;

  @end
@接口todd\u learningViewController:UIViewController{
}
-(iAction)拍照:(id)发送者;
@属性(弱、非原子)IBUIImageView*pictureView;
@结束

使您的类实现
UINavigationControllerDelegate
,此警告消息将消失。此协议中的所有方法都是可选的,因此您不必修改实现类


我们为什么必须这样做,我仍在努力弄清楚,但目前这是解决方案。

现在我有四个错误,在我的实现文件中,“@implementation todd_learningViewController”上有三个错误,分别是“方法协议未实现”和语义问题:“未完成实现”。旧的错误仍然存在。谢谢这就是你的appDelegate类,为什么你要实现UIApplicationDelegate,如果不删除它,我不理解这个注释,你能解释一下吗?我的意思是说你已经实现了UIApplicationLegate,所以如果不需要,就删除这个委托,然后运行你的应用程序。让我们看看这是因为
UIImagePickerController
UINavigationController
的一个子类。
delegate
必须遵守这两个协议,因为图像选择器的导航控制器部分使用相同的
delegate
属性。