在UITableView的detailedTextLabel中连接两个字符串

时间:2012-06-11 09:52:51

标签: iphone uitableview ios5 sdk

嗨,我有这行代码。

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

我想使用两个objectForKeys。我有一个“城市”和“状态”键我希望他们在那个详细的TextLabel中放在一起。我该怎么做?

5 个答案:

答案 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];