0
我正在尝试使用UIImagePickerControl
执行presentViewController
以显示标准Camera Roll照片选取器。这在我的大部分应用程序中都是端到端的。它不起作用的地方是当我想在已经呈现的viewController
内使用imagePicker的时候;无法呈现呈现相册的视图。presentViewController--尝试在__上呈现__,__其视图不在窗口层次结构中
基本思想是我试图访问窗口对象上的rootViewController
,或者应用程序委托的持久tabBarController
(这是rootViewController
);这两个例子都是希望永远存在的顶级项目的例子。只是使用“自我”,否则最终会作为呈现它的局部视图。
有一个可靠的方式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];
});