私はcell-subtitleのフォーマットの問題を抱えています。セルのサブタイトルに表示したい文字列と数字があります
文字列は左揃え、数字は右揃えにする必要があります
私はそのようにそれを試しました:
rangeAutor = [rangeAutor stringByPaddingToLength:40-[rangeAutor length] withString:@" " startingAtIndex:0];
NSString *subTitle = [NSString stringWithFormat:@"by %@ %1.2f km", rangeAutor, rangeDistance];
cell.detailTextLabel.text = subTitle;
結果はここで見ることができます:-(フォーマットの問題
解決策についてのアイデアはありますか?
私は7つの評判しかないという事実のために、コメントに私の答えを書くことはできません:-(だから私はここでそれをやろうとします:
static NSString *const kIdentifier = @"SelectRange";
static NSInteger const kDistanceLabelTag = 1;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
UILabel *distanceLabel;
if (cell) {
distanceLabel = (UILabel *)[cell.contentView viewWithTag:kDistanceLabelTag];
} else {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:kIdentifier];
CGRect cellBounds = cell.bounds;
static CGFloat const kLabelHeight = 20.0f;
distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, cellBounds.size.height - kLabelHeight, cellBounds.size.width, kLabelHeight)];
distanceLabel.tag = kDistanceLabelTag;
distanceLabel.font = cell.textLabel.font;
distanceLabel.textColor = cell.textLabel.textColor;
distanceLabel.textAlignment = UITextAlignmentRight;
distanceLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[cell.contentView addSubview:distanceLabel];
}
UIImage *icon = [UIImage imageNamed:iconName];;
cell.imageView.image = icon;
cell.textLabel.text = rangeName;
cell.detailTextLabel.text = [@"by " stringByAppendingString:rangeAutor];
distanceLabel.text = [NSString stringWithFormat:@"%1.2f km", rangeDistance];
NSLog(@"RangeDistance: %1.2f", rangeDistance);
return cell;
メイオフを奪う
小さなことだけを変更しましたが、セルにrangeDistanceが表示されません:-(ログの出力は問題ありません