如何将值从TableView传递给详细视图控制器?
答
当tableView委托获取消息选择了tableView中的一行时,它会这样做。
答
我想探索Flyingdiver的答案。
将数据填充到数组中,然后从该数组中加载表。确保数组是一个类级别的对象(可在类级别访问,直到包含表视图的类为活)。
当你点击表格时,tableViewDelegate会调用didSelectRowAtIndexPath方法。 那里您将获得被点击的单元格的indexPath(包括Row和Section)。将这些索引路径映射到您的数据阵列。
现在详细的视图控制器采取适当的数据类型的属性数据。
in didSelectRowAtindexpath alloc对象的详细信息View Controller在属性中分配数据并将其推送或显示在表上。 - >数据可以是一个简单的密钥,根据它你可以从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];
}
希望帮助!