从模态UIViewController呈现UIImagePickerController

时间:2014-01-11 04:13:59

标签: ios objective-c uiviewcontroller segue

我想要它,以便用户可以从他们的相册中选择一张照片进入imageview。如果我使用push segue到具有执行动作的按钮的viewcontroller似乎工作正常,但当我将其更改为模态segue时,当我单击按钮运行该功能时没有任何反应。究竟是什么原因造成的?

方法:

- (IBAction)choosePhotoFromAlbum:(id)sender {
    UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
    imgPicker.delegate = self;
    imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self.navigationController presentViewController:imgPicker animated:YES completion:nil];
}

2 个答案:

答案 0 :(得分:1)

您正尝试从导航控制器中显示它,但您的视图控制器是模态的。改变

[self.navigationController presentViewController:imgPicker animated:YES completion:nil];

[self presentViewController:imgPicker animated:YES completion:nil];

答案 1 :(得分:1)

您正尝试从导航控制器中显示它,但您的视图控制器是模态的。所以写一下

 [self presentViewController:YourImagePickerController animated:YES completion:nil];.