我从CoreData中获取对象,如下所示
cell.nameLabel.text = [NSString stringWithFormat:@"%@",self.name];
cell.nameLabel.numberOfLines = 0;
cell.nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
如何在
null
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGSize constraintSize = CGSizeMake(286.0f, CGFLOAT_MAX);
UIFont *theFont = [UIFont systemFontOfSize:14.0f];
CGSize theSize;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
CGRect frame = [[self.mArray objectAtIndex:indexPath.row] boundingRectWithSize:constraintSize options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:@{NSFontAttributeName:theFont} context:nil];
theSize = frame.size;
}
else
{
theSize = [[self.mArray objectAtIndex:indexPath.row] sizeWithFont:theFont constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping];
}
return theSize.height;
}
null
如果在
只需在UITableViewCell类中实现一个静态方法,该方法能够根据提供的字符串和宽度计算单元格高度。细胞应该知道它是如何构造的,它会占用多少空间。
例如:
+ (CGFloat)heightForWidth:(CGFloat)width text:(NSString *)text {
CGFloat height = ... ;
return height;
}
尝试禁用情节提要中的自动布局,然后调用SizetOfit。
cell.nameLabel.text = [NSString stringWithFormat:@"%@",self.name];
cell.nameLabel.numberOfLines = 0;
cell.nameLabel.lineBreakMode = NSLineBreakByWordWrapping;
[cell.nameLabel sizeToFit];