作者热门文章
- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我正在尝试在我的 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/
我是一名优秀的程序员,十分优秀!