Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popovers cannot be presented from a view which does not have a window

What does this error indicate:

"Popovers cannot be presented from a view which does not have a window."
like image 577
a111 Avatar asked Jul 31 '10 05:07

a111


3 Answers

the thing that saved my life:

if (self.view.window != nil)
    [popoverController presentPopoverFromRect:CGRectMake(44, yCoord, 111, 111) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

by adding if condition it doesn´t crash anymore. I don´t really get it because the presentPopoverFromRect function is ALWAYS called. There is no situation where window would be nil but anyway it did the trick.

edit: I have this code in viewDidAppear. Nevertheless in most cases it's enough to move presentPopoverFromRect to viewDidAppear or didMoveToWindow but in my case for some reason the if condition was necessary.

like image 139
Mobile Developer Avatar answered Sep 20 '22 10:09

Mobile Developer


the view you're adding the popover to has to already have been added to a window with the "addSubview:" method.

Try waiting until

- (void) didMoveToWindow

is called for the view and then load the popover

like image 22
hey68you Avatar answered Sep 20 '22 10:09

hey68you


I got this problem.

I had a UITabBarController as the detail view, and I set the barButtonItem as the leftBarButtonItem on all three navigation controllers in the tab bar.

vcChart.navigationItem.leftBarButtonItem = barButtonItem;
vcAnalysis.navigationItem.leftBarButtonItem = barButtonItem;
vcTechnicals.navigationItem.leftBarButtonItem = barButtonItem;

Turns out only the last one added is valid, and the previous two would throw the exception when tapped on.

To fix it, I only set the leftBarButtonItem for the visible view controller, and just switched the barButtonItem to the visible view controller every time the user switched tabs.

like image 25
Lewis Anderson Avatar answered Sep 21 '22 10:09

Lewis Anderson