2012-07-08 65 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

相關問題