嗨,我在我的UILabel字段中使用了line,当我加载tableview控制器时,它工作得很好,但是当我向上和向下滚动时,它会开始裁剪字母并包装到另一行。下面是我在CellForRowAtIndexPath中使用的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"subjectCell" forIndexPath:indexPath];
// Configure the cell...
// Load and display subject photo image
UIImageView *subjectImageView = (UIImageView *)[cell viewWithTag:200];
subjectImageView.image = [UIImage imageNamed:subjectImages[indexPath.row]];
// Load and display subject label
UILabel *subjectLabel = (UILabel *)[cell viewWithTag:201];
subjectLabel.text = [subjectItems objectAtIndex:indexPath.row];
[subjectLabel sizeToFit];// call this to fit size of the label according to text
return cell;
}下面是我的originaly控制器的屏幕截图--原始加载:

在这里,在上下滚动之后,你可以看到描述被裁剪了。

感谢您为解决这一问题提供的任何帮助。
干杯
卡森
发布于 2015-09-05 17:24:14
将sizeToFit用于UILabel可能会在重用单元格的UITableView中造成这样的混乱。我能想到的解决方案之一是在调用sizeToFit之前为标签宽度设置帧的宽度,每次将文本分配给标签时都必须这样做。它应该是这样的:
CGRect frame = subjectLabel.frame;
frame.size.width = 100.0; //try to adjust this value
subjectLabel.frame = frame;
[subjectLabel sizeToFit];https://stackoverflow.com/questions/32414857
复制相似问题