2011-12-14 76 views
0

在我的iPad應用程序中,我通過編程添加了UISearchBar。 當我點擊searchBar時,會出現一個包含數據的表格。當我在表中的行挖掘,應該導航到新視圖導航到iOS中的新視圖

例如:

this is my screenshot

,當我在「依賴」點擊它應該表現出一個新的視圖。有關如何完成此任務的任何建議?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  { 
    ContentController *detailview = [[ContentController alloc]   initWithNibName:@"ContentController" bundle:nil];  
     detailview.detailString = [NSString stringWithFormat:@"%d",indexPath.row];  

    [self.view addSubView:detailView]; 
    [detailview release]; 
    } 

所以我添加了上面的代碼。我需要做其他事嗎?

回答

0

執行UITableViewDelegate方法didSelectRowAtIndexPath並將您的新視圖推送到導航堆棧上。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
// Some code 
// Initialize your new view here 
[self.navigationController pushViewContoller:yourViewController animated:YES]; 
} 
+0

做我需要拖動任何東西在我的.xib? – AndroidAddiction 2011-12-14 04:44:14

+0

你不需要拖動任何東西,但如果你想要的話,你可以將你的tableview的委託拖動到你的FilesOwner。只要確保你的類實現了`UITableViewDelegate`,然後在你的代碼中添加這個`yourTableView.delegate = self;` – visakh7 2011-12-14 05:02:49

0

嘗試 -

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  { 
    ContentController *detailview = [[ContentController alloc]   initWithNibName:@"ContentController" bundle:nil];  
     detailview.detailString = [NSString stringWithFormat:@"%d",indexPath.row]; 
    // [self.navigationController pushViewController:detailview animated:YES];  

    [self.view addSubView:detailView]; 
    [detailview release]; 
    }