Pregunta

Tengo esta advertencia:

"El receptor del mensaje 'sizewithfont: restringedTosize: linebreakmode:' es nulo y devuelve un valor de tipo 'cgsize' que será basura"

No lo entiendo. ¿Qué estoy haciendo mal?

Aquí está el código que estoy usando:

- (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;

}
¿Fue útil?

Solución

La causa es el siguiente segmento de código:

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

En eso en la parte delse, no se asigna ningún valor a la variable de texto. Entonces, permanece como nulo. Entonces, Xcode se queja de que es nulo.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top