Предупреждение: «Получатель сообщений» SizeWithFont: DendatedTosize: LineBreakMode: «Это ноль…»
-
24-10-2019 - |
Вопрос
Я получил это предупреждение:
«Приемник сообщения 'sizewithfont: DrendatedTosize: LineBreakMode:« равна нулю и возвращает значение типа' 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 жалуется на то, что это является нулевым.
Не связан с StackOverflow