Select 单击单元格时的 nsdictionary 键值

Select nsdictionary key values when cell clicked

这是我来自服务器 side.names 的 nsdictionary 输出在 tableview 上,但是当用户单击某个单元格时我想捕获该字典的 id

(
    {
    id = 1;
    name = "hair Dressing";
},
    {
    id = 2;
    name = Manicure;
},
    {
    id = 3;
    name = Cosmetics;
},
    {
    id = 4;
    name = "Make-Up";
},
    {
    id = 5;
    name = Solar;
}
)
//this is how i am printing data on tableview
cell.textLabel.text=[[dict valueForKey:@"name"]objectAtIndex:indexPath.row];

如果您在 cellForRowAtIndexPath 方法中正确获取名称详细信息,请使用以下方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

 NSLog(@"id==%@",[[dict valueForKey:@"id"]objectAtIndex:indexPath.row]);

 }

否则使用这个

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

 NSLog(@"id==%@",[[yourArrayName objectAtIndex:indexPath.row]objectForKey:@"id"]);

 }