PresentModalViewController: Animated: Crash after dismissal
I am currently having a problem with UIViewController
presentModalViewController:animated:
.
I am using the following code to set up and display a modal controller:
UINavigationController *navigationController = [[UINavigationController alloc] init];
AddSerialController *serialController = [[AddSerialController alloc] initWithNibName:@"AddSerial" bundle:nil];
[navigationController pushViewController:serialController animated:NO];
[self.parentViewController presentModalViewController:navigationController animated:YES];
[serialController release];
[navigationController release];
The app (running in the iPhone Simulator) crashes as soon as it is called dismissModalViewControllerAnimated:
. GDB says it crashes with objc_msgSend
.
If I comment out the last line of code (release of the navigation controller) everything works, but I am leaking UINavigationController
(as expected).
What the hell is going on here?
a source to share
When you create a UINavigationController, you must give it a root view controller:
AddSerialController *serialController = [[AddSerialController alloc] initWithNibName:@"AddSerial" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:serialController];
[serialController release];
[self.parentViewController presentModalViewController:navigationController animated:YES];
[navigationController release];
a source to share