Crash/SIGABRT when I try to present a UIPopoverController
Asked Answered
F

1

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];
Flowered answered 11/11, 2011 at 22:0 Comment(2)
is the cancel var an actual bar button item? (ie not nil)Cummine
I changed the code to an example that is easier to read in case others come across the same problem.Flowered
M
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.

Morice answered 11/11, 2011 at 22:33 Comment(4)
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.Flowered
Thank you so much. You have no idea how much this answer helped me. I would've never realized thisUnripe
Superb! Thank you sooooo much... I have same comment as @Andrew. It really helped me a lot. Thank you soo much.Sorus
@scott Sherwood could this also happen with a modal view controller?Arber

© 2022 - 2024 — McMap. All rights reserved.