I have @property(nonatomic,retain) UIPopoverController * popoverController;
I create my popover in my implementation class.
I use this:
- (void)createPopover:(NavigationController *)tempNavigation {
UIPopoverController *tempPopover = [[UIPopoverController alloc] initWithContentViewController:tempNavigation];
self.popoverController = tempPopover;
[self.popoverController setPopoverContentSize:CGSizeMake(width, height)];
tempPopover.delegate = self;
CGRect selectedRect = [self.tableView rectForRowAtIndexPath:indexPath];
[tempPopover presentPopoverFromRect:selectedRect inView:self.tableView permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[tempPopover release];
}
in this method I need to release my popover
i use this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
if (popoverController) {
[popoverController dismissPopoverAnimated:NO];
self.popoverController=nil;
[popoverController release];
}
return YES;
}
My question: this right way to release popover in this method. Or I must release popover in dealloc method only?
calls the setter. Given your property is declared as retain this will release the previous value and retain the new one (in this case it retains nil which does nothing).
calls release on popoverController which is now nil which does nothing. However you should not do it, if it had not been nil it would be over released (as release would be called on it also the next time you set the popoverController property).
You also have a problem when you set the property
the setter retains the value so you should autorelease it
And you should use ARC 🙂