Present Popover from Modal View Controller

I am trying to represent a Popover using a button in a UIModalPresentationPageSheet. It disables the application and returns the following message to the console:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a view which does not have a window.' 

My code works fine in a standard controller. As the message suggests, there is something regarding modality that prevents it from being displayed. I searched a lot for this topic, but did not find a solution. I have to believe that this is possible, since I saw something very similar in applications like 1Password.

Pointers and / or suggestions were highly appreciated.

+4
source share
3 answers

The following code seems to work for me, try the following:

 [_pPopOverController presentPopoverFromRect:CGRectMake(0, 0, 768, 900) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES]; 
0
source

I do not know which SDK you used, but I do not get any exceptions from 5.1. I am showing a popover from a text box and the following code works:

 - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField { [_popController presentPopoverFromRect:textField.frame inView:textField.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; return NO; 

}

0
source

I would argue that the problem is that you are passing a view controller instead of a view for the inView parameter. It tries to get .window for a UIViewController, and the UIViewControllers does not have one, UIViews do.

0
source

All Articles