How to Dismiss a Storyboard Popover?

I solved it creating a custom ixPopoverBarButtonItem that either triggers the segue or dismisses the popover being shown.

Up vote 3 down vote favorite 1 share g+ share fb share tw.

Below is a picture showing how to show a popover in Xcode 4.2 using storyboards: The problem is that I can't get the popover to disappear when I click the button that made it appear. When the button is pressed (first time) the popover appears. When the button is pressed again (second time) the same popover appears on top of it, so now I have two popovers.

According to iOS Human Interface Guidelines, I need to make the popover appear on the first tap and disappear on the second. How can I dismiss the popover when the user taps the toolbar button for a second time? Note: This was done in storyboard and interface builder, so there is currently no code for displaying the popover.

Objective-c uipopovercontroller xcode4.2 storyboard link|improve this question edited Mar 30 at 14:43 asked Nov 27 '11 at 16:57RazorSharp316218 96% accept rate.

Well that's a deal breaker for me. – Michael Dautermann Nov 27 '11 at 17:02 @MichaelDautermann I have edited the question – RazorSharp Nov 27 '11 at 17:09 How did you create the segue? Is the source end of the segue the button or the view controller?

Did you set any passthroughs for the segue? – rob mayoff Nov 27 '11 at 22:03 @rob I created the Segue through Interface builder. I would select the button and drag the Popover Segue to the Master View that I wanted.

The image above shows this. I am not sure what you mean by the last two questions in your comment. – RazorSharp Nov 27 '11 at 22:17 2 I created a new project using the "Single View Application" template and storyboard.

I dragged a button to the template's view and dragged out a second view controller. I control-dragged from the button to the second VC and chose Popover. When I run this, I can touch the button to make the popover appear and then when I touch anywhere outside the popover (including on the button), the popover disappears.

What did you do differently? – rob mayoff Nov 27 '11 at 23:46.

I solved it creating a custom ixPopoverBarButtonItem that either triggers the segue or dismisses the popover being shown. What I do: I toggle the action & target of the button, so it either triggers the segue, or disposes the currently showing popover. It took me a lot of googling for this solution, I don't want to take the credits for the idea of toggling the action.

Putting the code into a custom button was my approach to keep the boilerplate code in my view to a minimum. In the storyboard, I define the class of the BarButtonItem to my custom class: Then I pass the popover created by the segue to my custom button implementation in the prepareForSegue:sender: method: - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if (segue. Identifier isEqualToString:@"myPopoverSegue") { UIStoryboardPopoverSegue* popSegue = (UIStoryboardPopoverSegue*)segue; (ixPopoverBarButtonItem *)sender showingPopover:popSegue.

PopoverController; } } Btw... since I have more than one buttons triggering popovers, I still have to keep a reference of the currently displayed popover and dismiss it when I make the new one visible, but this was not your question... Here is how I implemented my custom UIBarButtonItem: ...interface: @interface ixPopoverBarButtonItem : UIBarButtonItem - (void) showingPopover: (UIPopoverController *)popoverController; @end ... and impl: #import "ixPopoverBarButtonItem. H" @interface ixPopoverBarButtonItem () @property (strong, nonatomic) UIPopoverController *popoverController; @property (nonatomic) SEL tempAction; @property (nonatomic,assign) id tempTarget; - (void) dismissPopover; @end @implementation ixPopoverBarButtonItem @synthesize popoverController = _popoverController; @synthesize tempAction = _tempAction; @synthesize tempTarget = _tempTarget; -(void)showingPopover:(UIPopoverController *)popoverController { self. PopoverController = popoverController; self.

TempAction = self. Action; self. TempTarget = self.

Target; self. Action = @selector(dismissPopover); self. Target = self; } -(void)dismissPopover { self.

PopoverController dismissPopoverAnimated:YES; self. Action = self. TempAction; self.

Target = self. TempTarget; self. PopoverController = nil; self.

TempAction = nil; self. TempTarget = nil; } @end ps: I am new to ARC, so I am not entirely sure if I am leaking here. Please tell me if I am...

Awesome! That is a great approach, and works well. ARC does most memory management for you, so you never need to use release, retain, etc. This is a godd article about ARC: longweekendmobile.com/2011/09/07/… – RazorSharp Apr 5 at 21:49.

I found the solution here stackoverflow.com/a/7938513/665396 In first prepareForSegue:sender: store in a ivar/property the pointer to the UIPopoverController and user that pointer to dismiss the popover in the subsequent invocations. ... @property (nonatomic, weak) UIPopoverController* storePopover; ... - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { if (segue. Identifier isEqualToString:@"My segue") { // setup segue here self.

StorePopover dismissPopoverAnimated:YES; self. StorePopover = ((UIStoryboardPopoverSegue*)segue). PopoverController; ... }.

Thanks for this. What I did is store the popoverController in the destinationViewController so I could easily access it later when my custom delegate would callback. – Besi Jan 21 at 21:48.

I've used custom segue for this. 1 create custom segue to use in Storyboard: @implementation CustomPopoverSegue -(void)perform { // "onwer" of popover - it needs to use "strong" reference to retain UIPopoverReference ToolbarSearchViewController *source = self. SourceViewController; UIViewController *destination = self.

DestinationViewController; // create UIPopoverController UIPopoverController *popoverController = UIPopoverController alloc initWithContentViewController:destination; // source is delegate and owner of popover popoverController. Delegate = source; popoverController. PassthroughViews = NSArray arrayWithObject:source.

SearchBar; source. RecentSearchesPopoverController = popoverController; // present popover popoverController presentPopoverFromRect:source.searchBar. Bounds inView:source.

SearchBar permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES; } @end 2 in view controller that is source/input of segue e.g. Start segue with action: -(void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { if(nil == self. RecentSearchesPopoverController) { NSString *identifier = NSStringFromClass(CustomPopoverSegue class); self performSegueWithIdentifier:identifier sender:self; } } 3 references are assigned by segue which creates UIPopoverController - when dismissing popover -(void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { if(self. RecentSearchesPopoverController) { self.

RecentSearchesPopoverController dismissPopoverAnimated:YES; self. RecentSearchesPopoverController = nil; } } regards, Peter.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions