Search code examples
iphoneobjective-cuitableviewuiviewcontrollerpopover

WEPopover does not work with UIViewController != UITableViewController


I use WEPopover (https://github.com/werner77/WEPopover) to display popovers on iPhone. Unfortunately it does not work if I use a general UIViewController for the contentViewController of it.

- (IBAction)showPopover:(id)sender
{
    UIViewController *contentViewController = [[PopoverContentViewController alloc] init];
    popoverController = [[WEPopoverController alloc] initWithContentViewController:contentViewController];
    popoverController.delegate = self;
    [popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:(UIPopoverArrowDirectionUp) animated:YES];
}

This just presents me a black popover with no content. The PopoverContentViewController is just a normal UIViewController generated by XCode without any changes to it. In my storyboard I added a ViewController, set its size to freeform and set the view's size to something lower than standard iPhone size. I set the owner of this viewcontroller the PopoverContentViewController. Unfortunately it does not show the content, it just shows a black popup.

If I change the the PopoverContentViewController to derive from UITableViewController it shows a table view, but that is not what I want.

What have I done wrong?


Solution

  • You likely need to load your view controller from the storyboard instead of instantiating it with alloc/init as you show.

    Something like this:

    UIViewController* contentViewController = [[UIStoryboard storyboardWithName: @"yourStoryboardName" bundle: nil] instantiateViewControllerWithIdentifier: @"yourViewControllerID"];