UIPopOverController + UITableView - Hide popover when cell is selected

Satyam picture Satyam · Oct 28, 2011 · Viewed 12.4k times · Source

In my Popover controller, i'm having a table view. On selection of a cell, I want to hide the pop over. How can I achieve it.

Answer

Satyam picture Satyam · Oct 29, 2011

In Header file of Root view controller:

@property (strong, nonatomic) UIStoryboardPopoverSegue* popSegue;

In the implementation file:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if( [[segue identifier] isEqualToString:@"popover"] )
    {
        NSLog(@"%@",[segue destinationViewController]);
        self.popSegue = (UIStoryboardPopoverSegue*)segue;

        [[segue destinationViewController] setDelegate:self];
    }
}

When ever you want to hide the pop over:

    if ([self.popSegue.popoverController isPopoverVisible]) 
    {
        [self.popSegue.popoverController dismissPopoverAnimated:YES];        
    }

In the table view, add a delegate and implement the delegate in root view controller. When the delegate method is called, use above code to dismiss the pop over.