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 9197563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:06:05+00:00 2026-06-17T22:06:05+00:00

I have a UIPopoverController stored in a strong property in my View Controller. When

  • 0

I have a UIPopoverController stored in a strong property in my View Controller. When the user rotates the iPad while the popover is visible, I dismiss the popover and set my property to nil.

if (self.popover != nil) {
    [self.popover dismissPopoverAnimated:NO];
    self.popover.delegate = nil;
    self.popover = nil;
}

When the code gets to self.popover = nil, ARC attempts to dealloc the UIPopoverController, but it crashes because it is supposedly still visible.

How am I supposed to dismiss and nil out the popover without it crashing?

  • 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-17T22:06:06+00:00Added an answer on June 17, 2026 at 10:06 pm

    First off, it would be advisable to check if the popover is being presented, this will conveniently also check if it is allocated:

    if ([self.popover isPopoverVisible]) {
        [self.popover dismissPopoverAnimated:NO];
    }
    

    Now, the issue is, you don’t get the delegate callback - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController if you dismiss the popover programmatically like this, but you need a strong reference to the popover until it is no longer visible.

    The way to do this is delay setting the property to nil until you return to the main run loop, as when you get back to the main run loop, all animations will have finished and thus the popover will no longer be visible.

    You will want to move the code setting the popover to nil into another method:

    - (void)releasePopover {
        self.popover.delegate = nil;
        self.popover = nil;
    }
    

    Then, in your rotation callback, add this method to fire on the main run loop, I like to do this by adding an invocation operation to the main run loop:

    if ([self.popover isPopoverVisible]){
        [self.popover dismissPopoverAnimated:NO];
        NSInvocationOperation *invocationOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(releasePopover) object:nil];
        [[NSOperationQueue mainQueue] addOperation:invocationOperation];
    }
    

    Finally, for the sake of cleanliness, you will probably want to call -releasePopover from inside your - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController callback.

    So, putting it all together:

    - (void)releasePopover
    {
        self.popover.delegate = nil;
        self.popover = nil;
    }
    
    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
    {
        if ([self.popover isPopoverVisible]){
            [self.popover dismissPopoverAnimated:NO];
            NSInvocationOperation *invocationOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(releasePopover) object:nil];
            [[NSOperationQueue mainQueue] addOperation:invocationOperation];
        }
    }
    
    - (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
    {
        [self releasePopover];
    }
    

    Having said all that, unless there is a good reason, you may just want to keep the popover around to reuse and only set it to nil when you get low-memory warnings and/or if your view is unloaded, as Chris Loonam’s answer mentioned

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a second view controller set to display in a UIPopoverController. I set
I have created a UIPopoverController and added it to a view controller when clicking
Possible Duplicate: UIPopovercontroller dealloc reached while popover is still visible Im creating a universal
I have one delegate file, one View Controller and one UIPopoverController My PopoverController is
I have a UIPopoverController named popover in another view. What I would like to
I have @property(nonatomic,retain) UIPopoverController * popoverController; I create my popover in my implementation class.
I have created a UIPopoverController and added it to a main view controller when
I have a UIPopOverController that shows a UIViewController with a UITableview in its view.
I have some UIPopoverController that were working fine in 4.3/5.0 iOS iPad. Now, with
Heey, In my iPad application I have a UIPopoverController with a UIViewController containing some

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.