调用控制器iOS时出错

时间:2015-04-08 10:10:55

标签: ios view uiimagepickercontroller transition

请帮助了解困难情况。

我意识到弹出窗口的方式已被描述为here

然后,在此窗口中,我决定从库中实现示例照片,但是当您打开新控制器时可能会收到以下警告:

Presenting view controllers on detached view controllers is discouraged <PopUpViewController: 0x7fbb405f4e90>.

示例照片按如下方式实施:

picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = NO;
        [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [self presentViewController:picker animated:YES completion:nil];

3 个答案:

答案 0 :(得分:0)

试试这个:

[self.view.window.rootViewController presentViewController:picker animated:YES completion:nil];

答案 1 :(得分:0)

也许您需要使用addChildController将弹出窗口作为子控制器添加到您显示它的控制器中,以便它不会从视图层次结构中分离出来?

你也可以尝试:另一种选择:

[self.parentViewController presentViewController:picker animated:YES completion:nil];

我在另一个线程上注意到这是一个解决方案。 Warning :-Presenting view controllers on detached view controllers is discouraged

在你的情况下,parentViewController可能是nil。

查看代码后编辑:

查看代码后,问题似乎如下:

1)弹出机制使用UIViewController的实例来创建布局,但实际上根本没有使用视图控制器。弹出机制(showInView:withImage:withMessage:animated:)从控制器中提取视图并将其添加到控制器的视图层次结构中,要求弹出窗口。因此,使用来自此弹出控制器实例的调用[self presentViewController...]的代码将从控制器呈现模态控制器,该控制器实际上未被使用。这是错误来自我认为的地方。您需要从原始控制器执行所有警报和模态演示,或者传入控制器以使用。

2)原始文章提到,因为只使用了控制器的容器视图,所以在创建它时需要对它进行强引用。所以你应该:

self.popViewController = [[PopUpViewController alloc] initWithNibName:@"PopUpViewController" bundle:nil];

解决方案:

我会扩展showInView...方法以传递控制器,该控制器拥有正在拼接弹出窗口的视图。然后使用此控制器显示任何模态控制器。所以改变:

- (void)showInView:(UIView *)aView withImage:(UIImage *)image withMessage:(NSString *)message animated:(BOOL)animated

- (void)showInController:(UIViewController *)aController inView:(UIView *)aView withImage:(UIImage *)image withMessage:(NSString *)message animated:(BOOL)animated

存储在PopUpViewController类的属性中传递的控制器引用,然后使用此属性调用presentViewController...

答案 2 :(得分:0)

我认为你在viewDidAppear方法中展示你的选择器。

如果是这样,那就是警告的原因......

请编写另一种方法,提供我们的选择器,然后延迟执行。

[self performSelector:@selector(yourMethod)
           withObject:nil afterDelay:0.0];

这会让你的presentationController在它呈现另一个之前完全加载。

我希望这有帮助..

修改

问题是,在你的行动表被解雇之前,你正在呈现挑选者

编辑2

也代替actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex,使用此方法获取点击的索引 -

- actionSheet:didDismissWithButtonIndex: