Ios uialertcontroller uiimagepicker 关闭:应用程序崩溃

Ios uialertcontroller uiimagepicker dismiss : app crash

我在 xcode 6 下创建了一个新应用程序,旧感冒不再起作用。 由于 iOS 8 我们使用 UIalertcontroller 来显示动作 sheet

我用它来启动照片库和 select 一张照片,但是当我想关闭选择器时,我的应用程序崩溃了,我不知道为什么。 在我的代码下面: UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.delegate = 自我; picker.allowsEditing = 是;

UIAlertController * uiViewActionSheet=   [UIAlertController
                             alertControllerWithTitle:@"Action"
                             message:nil
                             preferredStyle:UIAlertControllerStyleActionSheet];

UIAlertAction* chooseExisting = [UIAlertAction
                            actionWithTitle:NSLocalizedString(@"CHOOSE_EXISTING",@"Choose Existing")
                            style:UIAlertActionStyleDefault
                            handler:^(UIAlertAction * action)
                            {
                                //Do some thing here
                               picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

                                [self presentViewController:picker animated:YES completion:NULL];

                                [uiViewActionSheet dismissViewControllerAnimated:YES completion:nil];

                            }];

UIAlertAction* cancel = [UIAlertAction
                         actionWithTitle:@"Cancel"
                         style:UIAlertActionStyleCancel
                         handler:^(UIAlertAction * action)
                         {
                             [uiViewActionSheet dismissViewControllerAnimated:YES completion:nil];
                         }];

[uiViewActionSheet addAction:chooseExisting];
[uiViewActionSheet addAction:cancel];
[self presentViewController:uiViewActionSheet animated:YES completion:nil];    

图像选择器功能下方:

(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.uImageProfile.image = chosenImage;
self.lstatutImage.text = @"save";
[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];

if(picker.sourceType == UIImagePickerControllerSourceTypeCamera)
{
    UIImageWriteToSavedPhotosAlbum(chosenImage, nil, nil, nil);
}

__block NSString* resultSaveImage = @"";
//Save image onthe server
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    resultSaveImage = [controllerObject saveProfileImage:self.uImageProfile.image];

    dispatch_async(dispatch_get_main_queue(), ^{

        if(![resultSaveImage isEqualToString:@"\"ok\""])
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR",@"Error") message:resultSaveImage delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [alert show];
        }
    });
});

}

我的代码在这里崩溃了:

[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];

你有什么想法吗?

您正在关闭 picker,然后调用它:

[picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];

if(picker.sourceType == UIImagePickerControllerSourceTypeCamera) {...

您也不需要 [uiViewActionSheet dismissViewControllerAnimated:YES completion:nil]; 行!

尝试将关闭行移到末尾。如果仍然崩溃,可能是 presentingViewController 不存在了。