简体   繁体   English

关于表视图单元格indexpath.row

[英]About table view cell indexpath.row

I am getting error when i am assigning value to the cell like 我将值分配给单元格时出现错误

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

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

Error: [__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0x7fe5915d7180 错误:[__ NSCFString objectAtIndex:]:无法识别的选择器已发送到实例0x7fe5915d7180

If i write this statement 如果我写这句话

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

The last value is getting assigned. 最后一个值被分配。 If the count is 3 then output looks like this: 如果count为3,则输出如下所示:

Teja Teja公司

Teja Teja公司

Teja Teja公司

For every cell. 对于每个单元格。

You seem to be mismatching your code to interrogate the data structure unpacked from the JSON, you haven't included it, but it would seem like you need: 您似乎不匹配您的代码以查询从JSON解压缩的数据结构,但尚未包含它,但似乎您需要:

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

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

so you're indexing into the profiles array based on your table index, rather than always taking the first one, and then extracting the first name variable (where you were previously confused about arrays and strings). 因此,您要基于表索引将其索引到profiles数组中,而不是始终获取第一个,然后提取名字变量(您之前对数组和字符串感到困惑)。

This in your "cellForRowAtIndexPath:" method 这在您的“ 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