0

当一个人通过 UIImagePicker 从他们的图库中选择图像时,我正在尝试添加一个“你确定”按钮。这是我现在正在尝试的方法。

这是我展示 UIImagePicker 的方式

{
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentViewController:imagePicker animated:YES completion:nil];
}

一旦他们选择了图像,就会调用这个方法

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    myImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];

    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Do you want to set this image as your profile picture?"
                                                        delegate:self 
                                                        cancelButtonTitle:@"No" 
                                                        destructiveButtonTitle:@"Yes"
                                                        otherButtonTitles:nil];
    actionSheet.actionSheetStyle = UIActionSheetStyleAutomatic;
    [actionSheet showInView:[self.view window]];
}

然后,如果destructiveButton选择了,我将返回到我从中调用 UIImagePicker 的视图。

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == actionSheet.destructiveButtonIndex) {
        [self dismissViewControllerAnimated:YES completion:nil];
}

问题是我抛出了这个异常

-[UIActionSheet showInView:], /SourceCache/UIKit_Sim/UIKit-2903.2/UIActionSheet.m:5123 2013-10-10 22:14:55.735 Globism[1997:a0b] * 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序中的断言失败, 原因: '无效参数不满足: view != nil' *首先抛出调用堆栈:

我的猜测是它与它有关,[actionSheet showInView:[self.view window]];但我不知道如何解决它。有人可以指出我正确的方向吗?片段真的很有帮助!谢谢!

4

0 回答 0