【发布时间】:2014-10-06 20:14:16
【问题描述】:
我正在尝试使用UIImagePickerControl 执行presentViewController,以显示标准的相机胶卷照片选择器。这在我的大多数应用程序中都是端到端的。它不起作用的地方是当我想在已经呈现的viewController 中使用 imagePicker 时;无法呈现相册的视图。
基本思想是我尝试访问窗口对象上的rootViewController,或者应用程序委托的持久化tabBarController(即rootViewController);两者都是希望始终存在的顶级项目的示例。否则,仅使用“self”最终会成为呈现它的局部视图。
是否有可靠的方法在已呈现的视图中 presentViewController?
dispatch_async(dispatch_get_main_queue(), ^ {
// 1. attempt that works well elsewhere in app
[((AppDelegate*)[[UIApplication sharedApplication] delegate]).tabBarController presentViewController:self.imagePickerController animated:YES completion:nil];
// 2. this does nothing, no crash or action (_UIAlertShimPresentingViewController)
[[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:self.imagePickerController animated:YES completion:nil];
// 3. attempt off related internet suggestion, nothing happens
UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
while (topController.presentedViewController) {
topController = topController.presentedViewController;
}
[topController presentViewController:self.imagePickerController animated:YES completion:nil];
});
【问题讨论】: