У меня есть следующий код, показывающий объекты местоположения из NSArray в таблице, где каждый индекс NSArray представлен ячейкой в таблице в моем классе SecondViewController.m:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"restaurantcell";
LocationTableViewCell *cell = (LocationTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[LocationTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
Location *location = [locationList objectAtIndex:indexPath.row];
cell.locationName.text = location.name;
cell.locationAddress.text = location.address;
cell.locationDistance.text = location.distance;
return cell;
}
Мой соответствующий код в моем классе LocationTableViewCell.m выглядит так:
UILabel *rDistance = [[UILabel alloc] initWithFrame:CGRectMake(250, 0, 250, 20)];
lDistance.font = [UIFont systemFontOfSize: 13];
lDistance.numberOfLines = 0;
[self.contentView addSubview: lDistance];
locationDistance = lDistance;
[Дистанционное освобождение];
В настоящее время я получаю свойство расстояния, отображаемое со многими десятичными знаками. Свойство distance находится в Km, поэтому я хочу, чтобы оно было округлено до двух десятичных знаков, а к метке добавлялся суффикс «Km» с пробелом между свойством distance и «Km». Как бы я это сделал?