2012-01-09 36 views
0

這是目前我的代碼有:的tableview選擇新的觀點

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath { 
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; 
[self.navigationController pushViewController:detail animated:YES]; 

detail.rowNum.text = [NSString stringWithFormat:@"Image %d", (indexPath.row + 1)]; 

} 

它加載相同視圖控制器在我的表視圖的每一個細胞。我如何聲明,我只希望這發生在一個特定的行被選中時?所以例如,我會使上述適用於每個額外的行另一個實例只行1?或者,這可以在Xcode的故事板部分完成嗎?

更新:下面的答案我已經更新了代碼,這個工作正常,所以我想如果沒有其他人使用它很好?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *__strong)indexPath { 
if (indexPath.row == 0) { 
DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; 
[self.navigationController pushViewController:detail animated:YES]; 

detail.rowNum.text = [NSString stringWithFormat:@"Image %d", (indexPath.row + 1)]; 
} 

if (indexPath.row == 1) { 
    DetailViewController *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Forum"]; 
    [self.navigationController pushViewController:detail animated:YES]; 

} 

} 

回答

1

檢查indexPath.row ==是否爲所需的行。如果您的表格是靜態的,您只能在故事板中執行此操作。

+0

謝謝!這似乎工作正常。新代碼是否合適?我覺得我應該'別的'或以某種方式結束這個過程。這很新鮮.. – John 2012-01-09 14:12:45