Question

So, I've been poring over the internet and I can't get this issue resolved, because all the answers I've seen relate to a popover that has less view layers than mine, if that makes sense.

Anyway, I have a main view, which opens a popover, which contains a UINavigationController, which contains a UITableViewController. This is all set up in the Storyboard, with segues connected from the button tap to the popover navigation view controller.

I want to dismiss the popover when I select something on the UITableViewController, but all the solutions I've seen only work when I don't have a UINavigationController.

Any ideas? I'm all ears.

Was it helpful?

Solution 3

Ok, I think I've found an answer.

If anyone sees any issues I'd appreciate it if you'd let me know, but this is working for me so far:

In my main view controller (the one that opens the popover):

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue*) segue;
    currentPopover = [popoverSegue popoverController];
    currentPopover.delegate = self;

    UINavigationController *destinationNavController = (UINavigationController*)segue.destinationViewController;

    SelectServerToConnectViewController *destinationView = [destinationNavController.childViewControllers objectAtIndex:0];
    destinationView.parentPopover = currentPopover;
}

And in my SelectServerToConnectViewController:

-(void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    ServerItem *selectedServer = [CoreDataController getServerForIndex:indexPath.row];
    [parentPopover dismissPopoverAnimated:true];
}

OTHER TIPS

You should just have a property of your UIViewController that points to your UIPopoverController. When you create your UIViewController just link it up.

Use dismissPopoverAnimated: to dismiss it when tableView:didSelectRowAtIndexPath: is called.

http://www.raywenderlich.com/29472/ipad-for-iphone-developers-101-in-ios-6-uipopovercontroller-tutorial

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top