无法解雇imagePickerController

时间:2015-08-13 03:21:37

标签: ios objective-c uiimagepickercontroller

单视图控制器,带有单个图像视图:

- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];

if (self.imageView.image == nil) {
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:YES completion:nil];
}
else {   }
}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

[picker dismissViewControllerAnimated:YES completion:nil];
[self performSelector:@selector(composeEmail:) withObject:image afterDelay:1.0];
}

- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}

以下是MFMailComposer,但在选择“使用照片”后,imagePicker不会被忽略。' imagePicker似乎消失然后重新出现。
以下是ViewController的Gist链接: https://gist.github.com/FIDELHIMSELF/069609eb5489cf4723a1

我收到两条错误警告:

  

"警告:尝试显示其视图不在窗口层次结构中!"   和   "快照未渲染的视图会导致空快照。确保您的视图在屏幕更新后的快照或快照之前至少呈现一次。"

1 个答案:

答案 0 :(得分:0)

尝试解除视图控制器,如;

[picker dismissViewControllerAnimated:YES completion:nil];

所以例如 imagePickerControllerDidCancel 委托方法看起来像;

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [picker dismissViewControllerAnimated:YES completion:nil];
}