UIPopOverController + UITableView - hide popover when selecting a cell

In my Popover controller, I have a table view. When selecting a cell, I want to hide the popup. How can i achieve this.

+10
ios uitableview uipopovercontroller
Oct 28 '11 at 18:56
source share
4 answers

In the header of the Root view controller file:

@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 you want to hide the popup:

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

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

+9
Oct 29 '11 at 11:11
source share

Let me suggest a slightly different solution, which is to pass a popover controller link instead of a segue link.

In the implementation file of the source code view controller:

 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if ([[segue destinationViewController] isKindOfClass:[MyDestViewController class]]) { MyDestViewController* viewController = (MyDestViewController*)[segue destinationViewController]; UIStoryboardPopoverSegue* popoverSegue = (UIStoryboardPopoverSegue*)segue; [viewController setPopoverController:[popoverSegue popoverController]]; } } 

In the header file of the destination view controller:

 @property (weak, nonatomic) UIPopoverController* popoverController; 

In the implementation file of the destination view controller:

 @synthesize popoverController; 

The same file when you want to reject a popover:

 [popoverController dismissPopoverAnimated:YES]; 
+9
Dec 22 '11 at 15:02
source share

Apple documents recommend the following:

Rejecting popover programmatically requires a pointer to the popover controller. The only way to get such a pointer is to save it yourself, as a rule, in the content presentation controller. This ensures that the content presentation controller can reject the popover in response to the corresponding user actions.

http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewControllerCatalog/Chapters/Popovers.html

+1
Apr 18 '12 at 11:24
source share

in didSelectRowAtIndexPath try this code

 [viewController.popoverController dismissPopoverAnimated:YES]; 
+1
Nov 30 '12 at 6:45
source share



All Articles