Take the 2-minute tour ×

I have a segue that works for iPhone code to present the contents of a tableViewController embedded in a Navigation controller.

    UINavigationController *nc = (UINavigationController *)segue.destinationViewController;
    tvc = (MyTableViewController *)[nc.viewControllers lastObject];
    tvc.managedObjectContext = managedObjectContext;

tvc is a storyboard item, UITableViewController subclass, embedded in a navigationController. I am trying to find the easiest way to use the same setup on iPad, but present the contents in a popover, with a navigation controller, as opposed to presenting full screen as it's doing now. Else do I need to create a new viewController without using this setup?

share|improve this question

1 Answer 1

I created a custom UIStoryboardPopoverSegue, with the following perform code:

- (void)perform
    UITableViewController *src = (UITableViewController *) self.sourceViewController;
    MyController *dst = (MyController *) self.destinationViewController;

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:dst];

    UITableViewCell *cell = [src.tableView cellForRowAtIndexPath:[src.tableView indexPathForSelectedRow]];

    UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:navigationController];

    dst.popoverController = pop;

    CGSize size = CGSizeMake(475, src.view.frame.size.height);
    pop.popoverContentSize = size;

    [pop presentPopoverFromRect:cell.frame
       permittedArrowDirections:UIPopoverArrowDirectionUp | UIPopoverArrowDirectionDown

The downside of this is that it requires a seque that is custom to destination view controller. The upside is an easy to implement and support, well functioning popover segue.

share|improve this answer

Your Answer


