UIPopoverController和UIImagePickerController崩溃

这是我的观点的build立:

查看设置

UIBarButtonItem被点击时,它应该调出一个UIImagePickerController 。 我必须使用UIPopoverController来执行此操作,通过单击“重置”button来调用该操作,因为这在iPad上是必需的。 这是我的代码:

 -(IBAction) btnReset:(id)sender { [self chooseImage]; } -(void) chooseImage { if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { imagepicker = [[UIImagePickerController alloc] init]; imagepicker.allowsEditing = NO; imagepicker.delegate = self; imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagepicker.navigationBar.opaque = true; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { popoverController = [[UIPopoverController alloc] initWithContentViewController:imagepicker]; [popoverController presentPopoverFromBarButtonItem:reset permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES]; } else { [self presentModalViewController:imagepicker animated:YES]; } } } 

但是,当这个被调用时,视图崩溃,错误:

'NSInvalidArgumentException',原因:' – [UIPopoverController presentPopoverFromRect:inView:allowedArrowDirections:animated:]:无法从没有窗口的视图中呈现Popovers。

我究竟做错了什么? 先谢谢你。

它看起来像你正试图创build一个不在视图层次上的项目上的popup窗口。 如果这个方法被你的button调用,那么把方法头改为 – (void)chooseImage:(id)sender,并尝试从工具栏上的UIBarButton中展示popup窗口。

另外,如果你使用ARC(看起来像你),你必须坚持你的UIPopover,否则它将被释放时,仍然需要看到这个堆栈溢出后 。 你可能已经这样做了,但我想我会提高它作为一个我不明白是否/如何指定你的popoverController。