我收到了这个警告:
“消息‘sizeWithFont:constrainedToSize:lineBreakMode:’的接收者为 nil,并返回一个类型为‘CGSize’的值,这将是垃圾”
我不明白。我究竟做错了什么?
这是我正在使用的代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *text = nil;
NSUInteger row = indexPath.row;
if (indexPath.section == FIRST_SECTION) {
text = [_firstArray objectAtIndex:row];
} else if (indexPath.section == SECOND_SECTION) {
text = [_secondArray objectAtIndex:row];
} else {
text = nil;
NSLog(@"Wrong section");
}
UITableViewCell *cell = [self myCell];
UILineBreakMode lineBreakMode = cell.textLabel.lineBreakMode;
CGFloat width = _tableView.contentSize.width - (kTableCellHPadding*2 + tableCellMargin*2);
UIFont* font = cell.textLabel.font;
CGSize size = [text sizeWithFont:font
constrainedToSize:CGSizeMake(width, CGFLOAT_MAX)
lineBreakMode:lineBreakMode];
if (size.height > kMaxLabelHeight) size.height = kMaxLabelHeight;
return size.height + kTableCellVPadding*2;
}