UIPopoverController & UIImagePickerControl: “Popovers cannot be presented from a view which does not have a window”

I am trying to display a UIImagePickerControl in my iPad app. At first, the debugger told me that I needed to put it in a popover when doing it on an iPad. So I wrote the following code:

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

However, now I get the following error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a view which does not have a window.'

Any suggestions on what I should do? I know that self.view should have a window, but apparently... it doesn't?

Answers


This can happen if that bit of code is getting executed before the view is loaded, as self.view is still nil and therefore so is self.view.window.

Is it possible that you're doing this in an init method or some other place before the view is loaded (before -viewDidLoad: is called)?


Need Your Help

SQL Query - Multiple Joins on Same field

sql join foreign-keys

I need assistance building this query where i need to select different values from same table but different Unique Keys.

How to sync Perforce to Git while keeping existing Git commit hashes?

git perforce git-p4

I'm in the process of moving our repository to git. During the transition, engineers will still be submitting to the Perforce repository. While engineers are still working, I'll be switching system...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.