Search code examples
iphoneuiwindowuipopover

can we show UIPopOver over UIWindow


I'm working on application where I want show popover in

- (void)applicationWillEnterForeground:(UIApplication *)application 

app delegate function but application throwing exception

"'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a view which does not have a window.'".

I'm calling popOver like

[popOver presentPopoverFromRect:self.rootViewController.view.frame inView:self.rootViewController.view  permittedArrowDirections:0 animated:YES];

If I change code like

[popOver presentPopoverFromRect:self.rootViewController.view.frame inView:self.window  permittedArrowDirections:0 animated:YES];

the code work fine. So is it right to show popOver in appdelegates window?


Solution

  • The view isn't presented yet. That is why it doesn't have a window. Try adding that code to the root view controller's viewDidAppear method.