다음 표에서는 NSArray의 위치 개체를 테이블에 표시하고 각 NSArray의 색인을 표의 셀로 나타내는 코드를 보여줍니다 내 SecondViewController.m 클래스 :소수점 이하 두 자리로 반올림 한 표 셀의 거리 속성 표시 및 접미사 Km을 표시
는- (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; [lDistance release];
현재 소수점 이하 자리에 거리 속성이 표시됩니다. distance 속성은 Km이므로 소수점 두 자리로 반올림하고 접미사 "Km"을 distance 속성과 "Km"사이에 공백이있는 레이블에 추가합니다. 어떻게하면 좋을까요?
정말 감사합니다 다음 코드. 당신의 솔루션은 효과가있었습니다! 조심해. – syedfa