gpt4 book ai didi

Ios uialertcontroller uiimagepicker 忽略 : app crash

转载 作者:行者123 更新时间:2023-12-02 12:37:08 25 4
gpt4 key购买 nike

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

在图像选择器功能下方:

(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.presentingViewController dismissViewControllerAnimated:YES completion:nil];

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

您也不需要 [uiViewActionSheet DismissViewControllerAnimated:YES Completion:nil]; 行!

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

关于Ios uialertcontroller uiimagepicker 忽略 : app crash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28132315/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com