[英]How to pass value from TableView to Detail View Controller?
如何將值從TableView傳遞到Detail View Controller? 有人可以幫我嗎?
當tableView委托得到消息說tableView中的一行已被選中時,它將執行此操作。
我正在嘗試探索飛行潛水者的答案。
將數據填充到數組中,然后從該數組加載表。 確保數組是類級別的對象(可在類級別訪問,直到包含表視圖的類處於活動狀態)。
當您單擊表格時,tableViewDelegate將調用didSelectRowAtIndexPath方法。 在那里,您將獲得被單擊的單元格的indexPath(行和節)。 將那些索引路徑映射到您的數據數組。
現在詳細地講,視圖控制器采用具有適當數據類型的屬性數據。
在詳細信息View Controller的didSelectRowAtindexpath分配對象中,在屬性中分配數據並將其推送或呈現在表上。 ->數據可以是一個簡單的鍵,您可以基於該鍵從db或INTERNET中獲取數據,也可以是包含詳細數據的數據結構。
希望以上有幫助.....
假設您要選擇將您推送到DetailViewController
,請嘗試以下操作:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; {
DetailViewController * detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
// Set up any of the properties of your DetailViewController here. This is where the indexPath
// comes in handy, as you can look up your array that you used to fill in your cells!
[self.navigationController pushViewController:detailViewController animated:animated];
[DetailViewController release];
}
希望對您有所幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.