0

我能够像这样获取单元格的文本值:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSUInteger *row = [indexPath row];

    // NOW GET THE NAME AND ID FROM THAT ROW
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    NSString *cellText = cell.textLabel.text;    

    NSLog(cellText);    
}

但我需要能够获取该项目的 id,或者至少使用该行从数组中获取该项目。

这是我获取填充的 UITableView 数组的方法:

@synthesize items_array;

然后:

                 items_array = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

                 [self.itemList reloadData];

并且该数组具有 JSON,其中包含每个项目、item_id 和 item_name 等字段

那么当用户点击列表中的某个项目时,如何获取 id 字段?

谢谢!

4

2 回答 2

3
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *idField = [items_array objectAtIndex:indexPath.row];
}
于 2012-08-02T14:56:09.907 回答
1
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    NSDictionary *itemInfo = [items_array objectAtIndex:indexPath.row];
    NSString *itemID = [itemInfo objectForKey:@"item_id"];
}
于 2012-08-02T16:02:48.610 回答