嗨,我有这行代码。
cell.detailTextLabel.text = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"];
我想使用两个 objectForKeys。我有一个“城市”和“州”键,我希望它们放在那个详细的文本标签中。我该怎么做?
嗨,我有这行代码。
cell.detailTextLabel.text = [[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"];
我想使用两个 objectForKeys。我有一个“城市”和“州”键,我希望它们放在那个详细的文本标签中。我该怎么做?
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@, %@",
[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"],
[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"]];
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];
尝试这个:
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ %@",[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"city"],[[self->jsonArray objectAtIndex:indexPath.row] objectForKey:@"state"]];
你可以这样做:
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;
你尝试过这样的事情吗?
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];