質問

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

「メッセージの受信者 'sizewithfont:constaredtosize: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");
}

その他の部分では、テキスト変数に値は割り当てられていません。だから、それはnilのままです。したがって、Xcodeはそれがnullであると不平を言っています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top