UIImagePickerController 不会取消,收到有关分离的 ViewControllers 的消息
Posted
技术标签:
【中文标题】UIImagePickerController 不会取消,收到有关分离的 ViewControllers 的消息【英文标题】:UIImagePickerController won't cancel, getting message about detached ViewControllers 【发布时间】:2014-06-13 21:02:14 【问题描述】:我还没有看到这两个问题混在一起,所以我想我会问。
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>.
【问题讨论】:
Warning :-Presenting view controllers on detached view controllers is discouraged的可能重复 【参考方案1】:我以前也遇到过这个问题。
对我来说,事实证明是这样,尤其是在 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: withObject: afterDelay:]
这将删除消息。
【讨论】:
所以你编写启动相机方法而不是在 viewDidAppear 中执行最后一段代码(自我执行选择器)? 是的,在 viewdidAppear 中。像这样 -(void)viewDidAppear [self performSelector :showCamera withDelay:2.0];【参考方案2】:在树中查找 PhotoViewController 的层次结构。应该不是根吧。我发生了这种情况。 错误消息是字面的。
【讨论】:
以上是关于UIImagePickerController 不会取消,收到有关分离的 ViewControllers 的消息的主要内容,如果未能解决你的问题,请参考以下文章
UIImagePickerController 预览大小与实时大小不一样
UIImagePickerController 在 iOS 13 中不返回实时照片
UIImagePickerController 不尊重 iPad 上的视频最长持续时间
UIImagePickerController 相机不提供 URL