【发布时间】:2017-04-24 16:04:10
【问题描述】:
我正在尝试在 UIViewController 中设置 UITableView。对我来说效果很好。
首先,我做了什么:
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) 成功在原型单元格的所有字典中显示4个值。
即:email_id、mobile_no、name和relation。
注意:这里我得到 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 ??
}
请任何人都可以解决我的问题。帮助将是可观的。
【问题讨论】:
标签: ios objective-c uitableview dictionary