Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7820731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:24:34+00:00 2026-06-02T07:24:34+00:00

I’ve created a popover from a UIBarButtonItem using Xcode Storyboards (so there’s no code)

  • 0

I’ve created a popover from a UIBarButtonItem using Xcode Storyboards (so there’s no code) like this:

Xcode 5.0 Connections Inspector with Popover

Presenting the popover works just fine. However, I can’t get the popover to disappear when I tap the UIBarButtonItem 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 (or more if I continuer pressing the button). According to the iOS Human Interface Guidelines I need to make the popover appear on the first tap and disappear on the second:

Ensure that only one popover is visible onscreen at a time. You should not display more than one popover (or custom view designed to look and behave like a popover) at the same time. In particular, you should avoid displaying a cascade or hierarchy of popovers simultaneously, in which one popover emerges from another.

How can I dismiss the popover when the user taps the UIBarButtonItem for a second time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:24:38+00:00Added an answer on June 2, 2026 at 7:24 am

    EDIT: These problems appear to be fixed as of iOS 7.1 / Xcode 5.1.1. (Possibly earlier, as I haven’t been able to test all versions. Definitely after iOS 7.0, since I tested that one.) When you create a popover segue from a UIBarButtonItem, the segue makes sure that tapping the popover again hides the popover rather than showing a duplicate. It works right for the new UIPresentationController-based popover segues that Xcode 6 creates for iOS 8, too.

    Since my solution may be of historical interest to those still supporting earlier iOS versions, I’ve left it below.


    If you store a reference to the segue’s popover controller, dismissing it before setting it to a new value on repeat invocations of prepareForSegue:sender:, all you avoid is the problem of getting multiple stacking popovers on repeated presses of the button — you still can’t use the button to dismiss the popover as the HIG recommends (and as seen in Apple’s apps, etc.)

    You can take advantage of ARC zeroing weak references for a simple solution, though:

    1: Segue from the button

    As of iOS 5, you couldn’t make this work with a segue from a UIBarButtonItem, but you can on iOS 6 and later. (On iOS 5, you’d have to segue from the view controller itself, then have the button’s action call performSegueWithIdentifier: after checking for the popover.)

    2: Use a reference to the popover in -shouldPerformSegue...

    @interface ViewController
    @property (weak) UIPopoverController *myPopover;
    @end
    
    @implementation ViewController
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // if you have multiple segues, check segue.identifier
        self.myPopover = [(UIStoryboardPopoverSegue *)segue popoverController];
    }
    - (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
        if (self.myPopover) {
            [self.myPopover dismissPopoverAnimated:YES];
            return NO;
        } else {
            return YES;
        }
    }
    @end
    

    3: There’s no step three!

    The nice thing about using a zeroing weak reference here is that once the popover controller is dismissed — whether programmatically in shouldPerformSegueWithIdentifier:, or automatically by the user tapping somewhere else outside the popover — the ivar goes to nil again, so we’re back to our initial state.

    Without zeroing weak references, we’d have to also:

    • set myPopover = nil when dismissing it in shouldPerformSegueWithIdentifier:, and
    • set ourself as the popover controller’s delegate in order to catch popoverControllerDidDismissPopover: and also set myPopover = nil there (so we catch when the popover is automatically dismissed).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.