Ios uialertcontroller uiimagepicker解雇:app崩溃

时间:2015-01-25 01:38:56

标签: ios ios8 crash uiimagepickercontroller uialertcontroller

我在xcode 6下创建了一个新的应用程序,旧的冷却不再有用。 从iOS 8开始,我们使用UIalertcontroller来显示操作表

我用它来制作图片并选择一张图片,但是当我想要解雇这个选择器时,我的应用程序崩溃了,我不知道为什么。 在我的代码下面:     UIImagePickerController * picker = [[UIImagePickerController alloc] init];     picker.delegate = self;     picker.allowsEditing = YES;

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];    

在imagepicker函数下面:

(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];

你有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您正在解雇picker,然后调用它:

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

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

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

尝试将关闭线移动到最后。如果它仍然崩溃,那可能是presentViewController不再存在。