ipad - UIPopoverController & UIImagePickerControl : "Popovers cannot be presented from a view which does not have a window"

标签 ipad ios uiimagepickercontroller uipopovercontroller

我正在尝试在我的 iPad 应用程序中显示一个 UIImagePickerControl。起初,调试器告诉我,在 iPad 上执行此操作时,我需要将其放入弹出窗口中。所以我写了下面的代码:

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 400.0, 400.0) 
                         inView:self.view
       permittedArrowDirections:UIPopoverArrowDirectionAny 
                       animated:YES];

但是,现在我收到以下错误:Termating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a view which does not have a window.'

关于我应该做什么有什么建议吗?我知道 self.view 应该有一个窗口,但显然......它没有?

最佳答案

如果在加载 View 之前执行了那段代码,就会发生这种情况,因为 self.view 仍然是 nil,因此 self.view.window 也是.

是否有可能在加载 View 之前(在调用 -viewDidLoad: 之前)在 init 方法或其他地方执行此操作?

关于ipad - UIPopoverController & UIImagePickerControl : "Popovers cannot be presented from a view which does not have a window",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4006724/

相关文章:

ios - Firebase推送通知有效负载中的JSON字典在iOS上被读取为String

ios - AFNetworkActivityIndi​​catorManager 不会递减,因为表格单元格回收取消了图像请求

iOS5 使用 webkit-overflow-scrolling 滚动时图像消失 : touch

objective-c - 如何从下载的图像创建新的 ALAsset

iphone - 应用程序在后台运行时获取推送通知的自定义负载

ios - UIImagePicker 中的图像方向不正确

ios - ALAssetsLibrary无效或为null

iphone - 如何更改键盘 DONE 按钮,iPhone

ios - React Native 限制?

ios - 从 UIImagePickerController 返回的图像比原始图像小