【发布时间】:2012-02-16 21:02:37
【问题描述】:
我试图以模态方式呈现 UINavigationController 和 UITableViewController 作为它的根视图,但在按下按钮以呈现模态视图时,应用程序不断崩溃。
- (IBAction)flipToDefaultsViewController:(id)sender
{
RootTableViewController *controller = [[RootTableViewController alloc] initWithNibName:@"RootTableViewController" bundle:nil];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:controller];
nc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:nc animated:YES];
}
应用程序崩溃并显示消息:
[RootTableViewController numberOfSectionsInTableView:]:消息发送到释放实例0x5677b5
当我加载 Instruments 以进一步查看时,很明显创建了我的 UITableViewController 的两个实例,一个是 UINavigationController 的所有者,另一个是 UIKit。 UIKit 创建的实例是被释放并导致崩溃的实例。
当我将初始化从 initWithNibName:bundle: 更改为 init 时,UITableViewController 加载正常(我的 .xib 文件与类同名)。
我的问题是为什么会发生这种情况?
在将UITableViewController 添加到 UINavigationController 时,您是否应该不以这种方式初始化它?到目前为止,我一直在搜寻文档,但没有任何乐趣。
使用带有 ARC 的 iOS 5,但目标部署是 4.0。
【问题讨论】:
标签: ios initialization automatic-ref-counting