Avertissement: « Le récepteur du message 'sizeWithFont: constrainedToSize: lineBreakMode:' est nul ... »
-
24-10-2019 - |
Question
Je suis cet avertissement:
"Le récepteur du message 'sizeWithFont: constrainedToSize: lineBreakMode:' est nul et retourne une valeur de type 'CGSize' qui sera garbage"
Je ne comprends pas. Qu'est-ce que je fais mal?
Voici le code que je utilise:
- (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;
}
La solution
La cause est le segment de code suivant:
if (indexPath.section == FIRST_SECTION) {
text = [_firstArray objectAtIndex:row];
} else if (indexPath.section == SECOND_SECTION) {
text = [_secondArray objectAtIndex:row];
} else {
NSLog(@"Wrong section");
}
Dans ce dans la partie d'autre, aucune valeur est affectée à la variable texte. Ainsi, il reste aussi nul. Donc, XCode se plaint à ce sujet étant nul.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow