Reputation: 23
Hi I have this line of code.
cell.detailTextLabel.text = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"];
I want to use two objectForKeys. I have a "city" & "state" key I would like them to put together in that detailedTextLabel. How would I do that?
Upvotes: 0
Views: 668
Reputation: 1841
NSString *city = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"];
NSString *state =[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"city is : %@ state is: %@", city, state];
Upvotes: 1
Reputation: 7501
Did you try something like this ?
NSString *city = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"];
NSString *state = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"];
cell.detailTextLabel.text = [[NSString alloc]initWithFormat:@"%@ %@",city,state];
Upvotes: 0
Reputation: 17186
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@",
[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"],
[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"]];
Upvotes: 5
Reputation: 3408
Try this:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@",[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"],[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"]];
Upvotes: 1
Reputation: 45598
You can do something like this:
NSString *city = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"];
NSString *state = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"];
NSString *combined = [NSString stringWithFormat:@"%@ (%@)", city, state];
cell.detailTextLabel.text = combined;
Upvotes: 1