I am getting a crash when I popToRootViewController, this is the way I have it set up.
I have:
@property (nonatomic, retain) UIPopoverController *popover;
in dealloc:
[popover release];
when a button is pressed
if (self.popover == nil) {
DetailViewController *detailView = [[[DetailViewController alloc] init] autorelease];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(GoToTest:) name:TestDetailPressed object:detailView];
self.popover = [[[UIPopoverController alloc] initWithContentViewController:detailView] autorelease];
self.popover.delegate = self;
[self.popover presentPopoverFromRect:frame inView:self.scrollView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
My DetailViewController is essentially just a UITableView. When a row is selected, I post a notification back to this current class for GoToTest:
- (void)GoToTest:(NSNotification *)notification {
if ([self.popover isPopoverVisible]) {
[self.popover dismisspopoverAnimated:YES];
[self handleDismissedPopover:self.popover];
}
[self.navigationController popToRootViewControllerAnimated:NO];
}
- (void)handleDismissedPopover:(UIPopoverController *)popoverController {
self.popover = nil;
self.popover.delegate = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:TestDetailPressed object:nil];
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
[self handleDismissedPopover:popoverController;
}
When I run it in Instruments, I get the zombie message for
-[UIPopoverController _popoverDismissAnimationCompleted]
and the UIViewController has a refCt of -1 at that point.
You probably want to change
self.popover = nilltopopover = nilbecause the first (self.popover = nil) will call the property setter, which releases the old value and sets the member to nil. Also, put the delegate nil before the property nil.To fix, change this:
To:
And if that doesn’t work, set NSZombieEnabled, MallocStackLogging, and guard malloc in the debugger. Then, when your App crashes, type this in the gdb console:
Replace
0x543216with the address of the object that caused the crash, and you will get a much more useful stack trace and it should help you pinpoint the exact line in your code that is causing the problem.See this article for more detailed instructions.