为什么UITableViewCell文本没有左对齐?

时间:2012-10-13 12:38:42

标签: ios uitableview

为什么这样:

 Profile *showProfile = [[Profile alloc] init];

    showProfile = [profileArray objectAtIndex:indexPath.row];

    if([[showProfile lastName] length] > 0){
       NSString *cellValue = [NSString stringWithFormat:@"%@ %@", [showProfile lastName], [showProfile firstName]];
       [[cell textLabel] setText:cellValue];

    }

显示UITableViewCell上的文本不在左侧。我无法发布图片给你看,但是这让我很伤心。文本似乎更集中。

但如果我这样做:

Profile *showProfile = [[Profile alloc] init];

        showProfile = [profileArray objectAtIndex:indexPath.row];

        if([[showProfile lastName] length] > 0){
           NSString *cellValue = @"This is aligned properly";
           [[cell textLabel] setText:cellValue];

        }

文字很好。

1 个答案:

答案 0 :(得分:0)

你确定你的姓氏前面没有任何空格吗?尝试修剪字符串,如下所示:

[[cell textLabel] setText:[cellValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

另请注意,您目前正在分配一个从未使用过的Profile对象!而不是:

Profile *showProfile = [[Profile alloc] init];
showProfile = [profileArray objectAtIndex:indexPath.row];

只需使用:

Profile *showProfile = [profileArray objectAtIndex:indexPath.row];

否则,您始终首先创建一个您从不使用的新配置文件对象,这需要时间。