大家好我对我有问题tableview
,我制作Cell with uilabel
with SizeToFit
然后计算UILabel
高度设置单元格高度一切正常,除非我滚动我tableView
的文本变得奇怪,如每行一个字符:
我的TableViewVell
方法是:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
UILabel *label = (UILabel *)[cell viewWithTag:1];
label.text = [someArray objectAtIndex:indexPath.row];
// Set the UILabel to fit my text;
messageLabel.lineBreakMode = UILineBreakModeWordWrap;
messageLabel.numberOfLines = 0;
[messageLabel sizeToFit];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
Cell Height保持正确的大小问题只有UILabel
...这是我加载视图时的结果: …