如何通过UIImagePicker从库中选择图像时添加UIActionSheet

时间:2013-10-11 04:36:18

标签: ios uiimagepickercontroller uiactionsheet

当一个人通过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'而终止app,原因:'无效的参数不满足:view!= nil' * 首先抛出调用堆栈:

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

0 个答案:

没有答案