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];
});