I got this warning:
"The receiver of message 'sizeWithFont:constrainedToSize:lineBreakMode:' is nil and returns a value of type 'CGSize' that will be garbage"
I don't get it. What am I doing wrong?
Here's the code I'm using:
- (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;
}
The cause is the following code segment:
if (indexPath.section == FIRST_SECTION) {
text = [_firstArray objectAtIndex:row];
} else if (indexPath.section == SECOND_SECTION) {
text = [_secondArray objectAtIndex:row];
} else {
NSLog(@"Wrong section");
}
In that in the else part, no value is assigned to the text variable. So, it remains as nil. So, XCode complains about it being null.
精彩评论