NSArray中的数据是一个JSON对象,看起来像这样:
<modelObject 0x1714abe0> {
key = 165825004;
value = Hello I am the data
}
数组中大约有20个这样的对象,我正试图在UITableView单元格中显示该对象的"值"。
在"(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
"中,我做:
cell.textLabel.text = [self.myArray objectAtIndex:indexPath.row];
崩溃时出现错误:
[modelObject length]: unrecognized selector sent to instance 0x1714abe0"
我假设它会抛出错误,因为我有2个键值对,或者因为它是JSON数据。我该如何处理?我只想在单元格上显示"值"属性中的数据,即在这种情况下,我想在单元格中显示"你好,我是数据"。
您应该以这种方式访问的值
cell.textLabel.text = [[self.myArray objectAtIndex:indexPath.row]objectForKey:@"key"];
或
cell.textLabel.text = self.myArray[indexPath.row][@"key"];
在cellForRowAtIndexPath中放入这行代码。。。employeeName数据取自将JSON数据放入的字典
cell.textLabel.text = [NSString stringWithFormat:@"%@",[[self.data objectAtIndex:indexPath.row]employeeName]];