单击单元格时选择nsdictionary键值

时间:2015-01-14 08:13:05

标签: ios objective-c uitableview nsdictionary

这是我在服务器端的nsdictionary输出.name是在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];

1 个答案:

答案 0 :(得分:0)

如果您在 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"]);

 }