Hello,
I am relatively new to Cocoa programming, and some aspects of memory managing are still troubling me.
In this case, I am creating a UINavigationController using the alloc message, and initialising it with a UIView controller. Then, I am presenting the view modaly by passing it to the presentModalViewController method. Below is the code:
- (void)tableView:(UITableView *)tableView
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Tapped on disclosure button");
NewPropertyViewController *newProperty = [[NewPropertyViewController alloc]
initWithDictionary];
newProperty.editProperty = [fetchedResultsController objectAtIndexPath:indexPath];
UINavigationController *newPropertyNavigationController = [[UINavigationController
alloc]
initWithRootViewController:newProperty];
[newProperty setPropertyDelegate:self];
[self presentModalViewController:newPropertyNavigationController animated:YES];
[newProperty release];
[newPropertyNavigationController release];
}
According to the retain count rules, if I send the message "alloc" to a class, an instance of that class is returned with retain count 1, and I am responsible for releasing it. In the above code, I release the newPropertyNavigationController instance after passing it to the modalViewController and presenting it. When I dismiss the modal view, the app crashes.
If I comment out the last line, the app doesn't crash.
Why is this happening? Is the particular alloc/init message to the UINavigationController working differently to the way it works in other classes, ie. is it perhaps returning an autoreleased instance?
Thanks!
Peter