Search code examples
iosobjective-cxibuipopovercontroller

UIPopViewController not working


I have an xib file with a .h and .m linked. In the xib there is a UIView with a textView. What I would like to do with that view is open it as a UIPopViewController when you click a button.

Here is my code:

- (IBAction)thisButton:(id)sender
{
    popViewController *popVC = [[popViewController alloc] initWithNibName:@"popViewController" bundle:nil];

    self.pop = [[UIPopoverController alloc] initWithContentViewController:popVC];

    [self.pop setPopoverContentSize:CGSizeMake(220, 120) animated:YES];
    [self.pop presentPopoverFromRect:[(UIButton *)sender frame] inView:self.view
                   permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}

It crashed with the following error.

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.'

I don't understand the error.


Solution

  • You can use UIPopoverController only in iPad application.

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        // for iPads
        // here you can use UIPopoverController   
    } else
    {
        // for iPhones
    }