0

私はこの警告を受けました:

「メッセージ'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;

}
4

1 に答える 1

1

原因は次のコードセグメントです。

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

その中で、elseの部分では、テキスト変数に値が割り当てられていません。したがって、それはゼロのままです。したがって、XCodeはそれがnullであると文句を言います。

于 2011-03-15T06:43:06.597 に答える