Pergunta

The data inside my NSArray is a JSON object which looks like this:

<modelObject 0x1714abe0> {
  key = 165825004;
  value = Hello I am the data
}

There are about 20 such objects in the array and I am trying to display the "value" from this object on a UITableView cell.

In "(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath" I do:

cell.textLabel.text = [self.myArray objectAtIndex:indexPath.row];

which crashes with an error:

[modelObject length]: unrecognized selector sent to instance 0x1714abe0"

I am assuming its throwing error because I have 2 key-value pairs or because its a JSON data. How do I handle this? I just want to display the data in "value" attribute on the cell i.e. in this case I want to display "Hello I am the data" on the cell.

Foi útil?

Solução

You should acesss value in this way

cell.textLabel.text = [[self.myArray objectAtIndex:indexPath.row]objectForKey:@"key"];

OR

cell.textLabel.text = self.myArray[indexPath.row][@"key"];

Outras dicas

In cellForRowAtIndexPath put this line of code... employeeName data taken from dictionary into which JSON data is put

cell.textLabel.text = [NSString stringWithFormat:@"%@",[[self.data objectAtIndex:indexPath.row]employeeName]];

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top