我没有看到这两个问题加在一起,所以我想我会问。
PhotoViewController
-(void)viewDidAppear:(BOOL)animated
{
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentViewController:picker animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = info[UIImagePickerControllerEditedImage];
if(!image) image = info[UIImagePickerControllerOriginalImage];
picker.delegate = self;
[self setPhotoForNextVC:image];
[self dismissViewControllerAnimated:YES completion:nil];
[self performSegueWithIdentifier:@"givePhotoToGiveDetailsSegue" sender:self];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
选择照片有效,但是当我按下取消时,UIImagePickerController会不断恢复,我收到错误:
Presenting view controllers on detached view controllers is discouraged <UINavigationController: 0x10b38b560>.
答案 0 :(得分:0)
我之前也遇到过这个问题。
对我而言,事实证明是这样,尤其是在ViewDidAppear中。 操作系统不希望出现新的控制器。
制作另一种处理此问题的方法。
(void)bringUpCameraController {
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]){
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
[self presentViewController:picker animated:YES completion:NULL];
} 我的解决方法:[self performSelector:&lt;(bringUpCameraController)&gt; withObject:其中(无)&GT; afterDelay:其中(2.0)&GT;]
这将消除信息。