UINavigationController不会推送其他视图控制器?

时间:2012-07-08 19:48:59

标签: ios uitableview sdk uinavigationcontroller

所以我在我的app的委托中创建了一个UINavigationController,并用我的RootViewController实例初始化它。 UINavigationController被添加为应用程序UIWindow的子视图。 (如果重要的话,我的RVC有一个自定义初始化程序。)

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
              _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

              _viewController = [[RootViewController alloc] initWithPath:@"/private/var/mobile/"];
              _viewController.title = @"mobile";

              UINavigationController *nav1 = [[[UINavigationController alloc] initWithRootViewController:_viewController] autorelease];

              //This part I'm not sure about as well
              [_window addSubview:nav1.view];
              [_window makeKeyAndVisible];

    return 0;
    }

有了这些信息,我试图从UITableView将另一个RVC实例推送到导航堆栈,如下所示:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
              //I've tried it without the if statement as well
              if(indexPath.section == 0){
                      RootViewController *detailView = [[RootViewController alloc] initWithPath:launchDirectory];
                      detailView.title = relativeDirectory;
                      [self.navigationController pushViewController:detailView animated:YES];

另外请注意,我的RVC tableview的数据源和委托已设置为" self"。

我的问题是:即使我在桌子上选择一行,为什么视图保持不变? 表格没有推到新表格,我在选择一行后仍然看到相同的单元格内容。换句话说,没有任何事情发生......

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

您的导航控件可能是nil,这意味着您的-autorelease有点太多了。通常,导航控制器会一直存在,直到委托的dealloc方法被调用,因此将其释放到那里。