使用带有didSelectRowAtIndexPath的字典

时间:2010-08-08 17:42:33

标签: iphone objective-c uitableview didselectrowatindexpath

我正在尝试从所选单元格中获取跟踪名称,并将其传递给didSelectRowAtIndexPath中的下一个视图。我该怎么做? http://pastebin.com/bgXNfjie

1 个答案:

答案 0 :(得分:1)

如果我理解正确,那么这不是一件大事。您只需要在TrailViewController中创建一个属性来保存您的值并将其指定为:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        TrailViewController *trailViewController = [[TrailViewController alloc] initWithNibName:@"TrailViewController" bundle:[NSBundle mainBundle]];
        NSDictionary *dict = [rows objectAtIndex: indexPath.row];
        trailViewController.trailName = [dict objectForKey:@"name"];
        [self.navigationController pushViewController:trailViewController animated:YES];
        [trailViewController release];
}

您可能希望将完整的NSDictionary分配给TrailViewController的属性,而不仅仅是名称,但这取决于您。我希望我能帮忙......