2011-01-26 48 views
2

這是我的第一篇文章,所以請溫和。如何從rootViewController中的多級導航更新detailViewController.detailItem

我在xcode中使用基本的基於Split View的應用程序,但已經編輯它,以便rootViewController不會簡單地更新detailViewController,而是將新的UITableViewController(taskViewController)推入導航堆棧。

我的問題是,沒有任何反應,當我現在請從我taskViewController如下:

detailViewController.detailItem = [NSString stringWithFormat:@"Row %d", indexPath.row]; 

如果我把這個從RootViewController的,而不是推一個新的UITableView到堆棧,它的工作原理。

下面是RootViewController的我的代碼時,選擇單元格:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    TaskViewController *taskViewController = [[TaskViewController alloc] init]; 

    taskViewController.title = [NSString stringWithFormat:@"Unit %d",indexPath.row]; 

    [self.navigationController pushViewController:taskViewController animated:YES]; 

    [taskViewController release]; 
} 

難道我做錯了嗎?我是否在UISplitViewController的rootViewController中正確使用導航控制器?

回答

5

您的rootViewController可以訪問detailViewController,因爲它對它有一個參考。如果您將新控制器推入導航堆棧,則其而不是會自動了解DetailViewController。

你有沒有NSLog'd detailViewController在你的taskVC中看看它是否有指針?

你通常會設置這個當你像這樣創造的:

- (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     TaskViewController *taskViewController = [[TaskViewController alloc] init]; 

     taskViewController.title = [NSString stringWithFormat:@"Unit %d",indexPath.row]; 

     taskViewController.detailViewController = self.detailViewController; 

     [self.navigationController pushViewController:taskViewController animated:YES]; 

     [taskViewController release]; 
    } 
+0

太棒了!我只是假設UISplitViewController負責所有這些。謝謝 – Peetz 2011-01-26 21:30:25