我得到了这样的警告:

“消息的接收器'sizewithfont:CondrachatedTosize: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;

}
有帮助吗?

解决方案

原因是以下代码段:

if (indexPath.section == FIRST_SECTION) {
    text = [_firstArray objectAtIndex:row];
} else if (indexPath.section == SECOND_SECTION) {
    text = [_secondArray objectAtIndex:row];
} else {
    NSLog(@"Wrong section");
}

在其他部分中,没有任何值分配给文本变量。因此,它仍然像零一样。因此,Xcode抱怨它为无效。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top