Objective c iPad在显示照片或拍照时崩溃--无源代码视图

Objective c iPad在显示照片或拍照时崩溃--无源代码视图,objective-c,ipad,uipopovercontroller,uialertcontroller,Objective C,Ipad,Uipopovercontroller,Uialertcontroller,在带有错误消息的iPad上运行时,以下代码崩溃: ()应该有一个非零 在演示文稿出现之前设置sourceView或barButtonItem。” 但是,在我的代码中有以下内容,我使用断点和控制台优先级进行了检查,以确保sourceview和barbutton不为零。我需要做什么来避免这种情况?这个错误只出现在iPad上。以下是导致故障的方法: - (void)showChooseImageOptions { UIAlertController *alertController = [UIAler

在带有错误消息的iPad上运行时,以下代码崩溃:

()应该有一个非零 在演示文稿出现之前设置sourceView或barButtonItem。”

但是,在我的代码中有以下内容,我使用断点和控制台优先级进行了检查,以确保sourceview和barbutton不为零。我需要做什么来避免这种情况?这个错误只出现在iPad上。以下是导致故障的方法:

- (void)showChooseImageOptions {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *chooseAction = [UIAlertAction actionWithTitle:@"Choose From Photos" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
    [self showLibrary];


}];
UIAlertAction *takeAction = [UIAlertAction actionWithTitle:@"Take Photo" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
    [self showCamera];

}];
self.directionsTextView.text=@"";
[alertController addAction:chooseAction];
[alertController addAction:takeAction];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {



    if (self.imageView.image)   {
        self.directionsTextView.text=@"Tap the circle to change the image";
    } else{
        self.directionsTextView.text=@"Tap the blue circle to choose or take an image";


    }

}];


[alertController addAction:cancelAction];
alertController.view.tintColor=[ColorSuperclass returnApplicationMainColor];






    alertController.popoverPresentationController.barButtonItem = self.navigationItem.rightBarButtonItem;


if ( [alertController respondsToSelector:@selector(popoverPresentationController)] ) {

    // at least iOS8

    alertController.popoverPresentationController.sourceView = self.view;


}

[self presentViewController:alertController animated:YES completion:nil];
}
showCamera和showLibrary方法只不过是:

-(void)showCamera   {
if (TARGET_IPHONE_SIMULATOR)    {
    //do nothing, the simulator cannot handle pressing the take photos...
} else{
    [self showImagePickerForSourceType:UIImagePickerControllerSourceTypeCamera];
}
}

- (void)showLibrary {
[self showImagePickerForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
以及“显示源类型”方法:

- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationPopover; //this line is very important, because otherwise, the tab bar could go out of scope (a consequence of using modal segues and tab controllers!)
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
imagePickerController.allowsEditing = YES;
[self presentViewController:imagePickerController animated:YES completion:nil];
}

不相关,但您甚至不应该添加“拍照”按钮,除非设备/模拟器支持拍照。“从照片库中选择”按钮也是如此。每个都应该用适当的
if
语句包装,以确保该操作得到支持。当然,所有苹果设备都支持这一点。为了安全起见,您使用的是IPHONE/IPAD模拟器布尔值(我忘记了确切的名称),如果是布尔值,只需返回方法earlyPerhaps这就是您的意思?否。使用提供的方法
UIImagePickerController isSourceTypeAvailable:
。不要做任何假设。即使设备有摄像头,也不意味着你真的可以拍照。好的,可以。为什么你认为iPad会给我带来这么多麻烦?谢谢