10

Hi I am at my wits end with what I am doing wrong here. I am using ios5 and nothing crashes if I do not call presentPopoverFromBarButtonItem. Has anyone experienced anything similar? I checked the apple developer forums, google, stack overflow and couldn't find anything.

Running bt on gdb didn't reveal any hints either.

UIViewController *viewTwo;
viewTwo = [[ViewTwo alloc] initWithNibName:@"ViewTwo" bundle:nil];

UIPopoverController *popover;
popover = [[UIPopoverController alloc] initWithContentViewController:viewTwo];  

[popover presentPopoverFromRect:[theButton bounds] 
                         inView:theButton 
       permittedArrowDirections:UIPopoverArrowDirectionLeft 
                       animated:NO];
CPrescott
  • 285
  • 3
  • 10

1 Answers1

22

I am assuming you are using ARC as I had this same issue. You have to hold on to the popup you have created otherwise its retain count will be decreased and it will be released when you get to the end of the methods scope.

So create a property and synthesise it until you no longer need it and remove it from screen, the set it to nil after it has been removed.

Scott Sherwood
  • 3,108
  • 25
  • 30
  • I actually just got it on my own and was coming back to respond that I had figured it out. If you are not using ARC (or just pre X-Code 4.2) you do not have to hold onto it was what was throwing me off. – CPrescott Nov 11 '11 at 23:24
  • Thank you so much. You have no idea how much this answer helped me. I would've never realized this – Andrew Apr 07 '12 at 14:05
  • 1
    Superb! Thank you sooooo much... I have same comment as @Andrew. It really helped me a lot. Thank you soo much. – iOS Monster Jul 10 '12 at 10:58
  • @scott Sherwood could this also happen with a modal view controller? – Sean Dunford Apr 30 '14 at 04:29