2010-11-27 35 views
1

基本上我添加一個子視圖到主窗口。這個子視圖有一個搜索欄和一個表格視圖。搜索欄起作用,它在表格視圖單元格上顯示一些數據。現在,當我點擊一個單元格時,它應該使用導航欄(w /後退按鈕)和該視圖中的表格加載另一個視圖。如何才能做到這一點?我嘗試了下面的代碼,它不起作用,它給了我一個錯誤 - 「' - [UIViewController _loadViewFromNibNamed:bundle:]加載了」DetailViewController「筆尖,但未設置視圖插口。如何打開一個新的UITableView時單擊表格單元格,並動態添加導航控制器

我試圖設置在DetailViewController.nib文件出口的,但它只是不會讓我。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:[[UITableViewController alloc]initWithNibName:@"DetailViewController" bundle:nil]]; 

    [self presentModalViewController:navigationController animated:YES]; 
    [navigationController release]; 

} 

回答

1

基本上你推細節視圖控制器到導航控制器。
我發表a sample code

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 


    DetailContactViewController *detailViewController = [[DetailContactViewController alloc] initWithNibName:@"DetailContactView" bundle:nil]; 
    detailViewController.contact = [contacts objectAtIndex:indexPath.row]; 
    // ... 
    // Pass the selected object to the new view controller. 
    [self.navigationController pushViewController:detailViewController animated:YES]; 

    [detailViewController release]; 

} 
相關問題