繁体   English   中英

关于表视图单元格indexpath.row

[英]About table view cell indexpath.row

我将值分配给单元格时出现错误

profileJson = dicData[@"profile"][0];

cell.userName.text = [[profileJson objectForKey:@"First_Name"] objectAtIndex:indexPath.row];

错误:[__ NSCFString objectAtIndex:]:无法识别的选择器已发送到实例0x7fe5915d7180

如果我写这句话

cell.userName.text = [profileJson objectForKey:@"First_Name"];

最后一个值被分配。 如果count为3,则输出如下所示:

Teja公司

Teja公司

Teja公司

对于每个单元格。

您似乎不匹配您的代码以查询从JSON解压缩的数据结构,但尚未包含它,但似乎您需要:

profileJson = dicData[@"profile"][indexPath.row];

cell.userName.text = [profileJson objectForKey:@"First_Name"];

因此,您要基于表索引将其索引到profiles数组中,而不是始终获取第一个,然后提取名字变量(您之前对数组和字符串感到困惑)。

这在您的“ cellForRowAtIndexPath:”方法中

NSDictionary *profileJson = dicData[@"profile"][indexPath.row];

NSString *userNameString = [profileJson objectForKey:@"First_Name"];

cell.userName.text = userNameString;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM