【问题标题】:Ios uialertcontroller uiimagepicker dismiss : app crashios uialertcontroller uiimagepicker 关闭:应用程序崩溃
【发布时间】:2015-03-23 19:33:34
【问题描述】:

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

我用它来启动照片库并选择一张图片,但是当我想关闭选择器时,我的应用程序崩溃了,我不知道为什么。 在我的代码下面: UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 选择器.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];    

图片选择器功能下方:

(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 小时......)

标签: ios ios8 crash uiimagepickercontroller uialertcontroller


【解决方案1】:

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

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

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

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

尝试将解雇线移到末尾。如果它仍然崩溃,则可能是presentingViewController 不再存在。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多