0

我目前遇到UIViewController's的问题presentModalViewController:animated:

我使用以下代码来设置和显示模态视图控制器:

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];

dismissModalViewControllerAnimated:应用程序(在 iPhone 模拟器中运行)一被调用就会崩溃。GDB 说它在objc_msgSend.

如果我注释掉最后一行代码(导航控制器的发布)一切正常,但我正在泄漏UINavigationController(如预期的那样)。

这到底是怎么回事?

4

1 回答 1

2

当你创建一个 UINavigationController 时,你应该给它一个根视图控制器:

AddSerialController *serialController = [[AddSerialController alloc] initWithNibName:@"AddSerial" bundle:nil];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:serialController];

[serialController release];

[self.parentViewController presentModalViewController:navigationController animated:YES];

[navigationController release];

于 2009-05-25T17:02:12.900 回答