2012-07-08 54 views
0

所以我在我的应用程序的委托中创建了一个UINavigationController,并使用我的RootViewController实例对其进行了初始化。 UINavigationController作为应用程序UIWindow的子视图添加。 (RVC我有一个自定义的初始化,如果该事项。)UINavigationController不会推送其他视图控制器?

- (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的数据源和委托已被设置为“自我”。

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

感谢您的任何帮助。

回答

1

您的导航控制器可能是nil,这意味着您的-autorelease有点太多了。通常情况下,导航控制器会一直持续到代理的dealloc方法被调用,所以在那里释放它。

+0

setRootViewController不在我的UIWindow类中。我正在使用SDK 3 btw兼容性。 – 2012-07-08 20:09:04

+0

然后忽略第一部分。第二部分依然如此。 – CodaFi 2012-07-08 20:32:23

+0

尽管这是一个新实例。一个新的变量。这就是为什么我为它创建了一个自定义初始化器。自定义初始化程序将创建从中填充表的数组。 -second-RVC实例具有与第一个不同的数组。我读到你可以推动同一个班级的不同实例。有点像使用多个UIAlertViews。 UIViewControllers没有什么不同。为了测试这个理论,我创建了一个与RVC类相同的DetailView类。仍然无法从父视图控制器(RVC)推送DetailView类。 – 2012-07-08 20:49:37

相关问题