嗨,我有这行代码。
cell.detailTextLabel.text = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"];
我想使用两个objectForKeys。我有一个“城市”和“状态”键我希望他们在那个详细的TextLabel中放在一起。我该怎么做?
答案 0 :(得分:5)
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@",
[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"],
[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"]];
答案 1 :(得分:1)
您可以这样做:
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;
答案 2 :(得分:1)
试试这个:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@",[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"],[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"]];
答案 3 :(得分:1)
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];
答案 4 :(得分:0)
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];