gpt4 book ai didi

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

转载 作者:技术小花猫 更新时间:2023-10-29 10:35:26 26 4
gpt4 key购买 nike

我正在尝试在我的 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com