0

嗨,我有这行代码。

cell.detailTextLabel.text = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"];

我想使用两个 objectForKeys。我有一个“城市”和“州”键,我希望它们放在那个详细的文本标签中。我该怎么做?

4

5 回答 5

5
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@",
                             [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"], 
                             [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"]];
于 2012-06-11T09:58:46.930 回答
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];
于 2012-06-11T10:02:25.400 回答
1

尝试这个:

cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@",[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"],[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"]];
于 2012-06-11T09:56:25.433 回答
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;
于 2012-06-11T09:56:15.260 回答
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];
于 2012-06-11T09:59:13.870 回答