gpt4 book ai didi

ios - 在iOS中单击UITableViewCell后如何获取字典中的键值?

转载 作者:行者123 更新时间:2023-12-01 17:22:17 25 4
gpt4 key购买 nike

我正在尝试设置 UITableView UIViewController 的内部.这对我来说可以。

首先,我做了什么:

1) 我从服务器得到这样的响应:

[{"email_id":"adas@faga.gs","id":66,"mobile_no":"1236547895","name":"asad","relation":"dsfs"},{"email_id":"raj@ghj.com","id":67,"mobile_no":"5632145412","name":"raj","relation":"xyz"},{"email_id":"surajsukale@gmail.com","id":68,"mobile_no":"8698819943","name":"suraj","relation":"self"}]

2) 成功在原型(prototype)单元格中的所有字典中显示 4 个值。

即: email_id , mobile_no , namerelation .

注:在这里我得到 5 个参数作为响应,但我只显示 4 个。

这是我为此所做的:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [menuItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"EmergencyContactCell";

EmergencyContactCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

NSDictionary *content = [menuItems objectAtIndex:indexPath.row];

cell.name.text = content[@"name"];
cell.email.text = content[@"email_id"];
cell.mobile.text =content[@"mobile_no"];
cell.relation.text =content[@"relation"];

return cell;
}

它非常适合我。

现在,我想要什么?

当我单击任何单元格时,我想获取该字典中的特定 ID。
我应该在这里做什么:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%ld",(long)indexPath.row);

// What should i do here is my question ??
}

请任何人都可以解决我的问题。帮助将是可观的。

最佳答案

我想你正在寻找类似的东西

NSDictionary *content = [menuItems objectAtIndex:indexPath.row];
NSNumber *number = content["id"];

如果您需要纯数据类型,请使用适当的属性,例如:
int iNumber = number.intValue;

关于ios - 在iOS中单击UITableViewCell后如何获取字典中的键值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41055969/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com