This is a simple question: why does the following code cause a "Control may reach end of-non-void function" warning? Under what circumstances would one of the two return statements not be hit? Would it be more standard coding practise to place the second return
statement outside of the else
block? This does silence the warning, but I'm curious as to why it exists at all.
- (CGFloat) tableView: (UITableView *) tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath
{
NSString *lineToFit = [[self.fetchedResultsController objectAtIndexPath: indexPath] line];
NSString *actorToFit = [[self.fetchedResultsController objectAtIndexPath: indexPath] actor];
CGSize lineSize = [lineToFit sizeWithFont: [UIFont boldSystemFontOfSize: 12.0f] constrainedToSize: CGSizeMake(320, 800)];
CGSize actorSize = [actorToFit sizeWithFont: [UIFont boldSystemFontOfSize: 12.0f] constrainedToSize: CGSizeMake(320, 800)];
if (shouldDisplayExtra) {
kExtraCellType cellType = [self cellIsGoingToContainExtraView];
if (cellType != kExtraCellTypeNone) {
[cellsToContainExtra setValue: [NSNumber numberWithInt: cellType] forKey: lineIDString];
return lineSize.height + actorSize.height + 200;
}
} else {
// Return the line height, actor height, plus a buffer.
return lineSize.height + actorSize.height;
}
}
You do have a condition that results in no return:
if shouldDisplayExtra
exist and cellType == kExtraCellTypeNone
then there is no return defined...
You should add an else block to the conditional:
if (cellType != kExtraCellTypeNone) {
[cellsToContainExtra setValue: [NSNumber numberWithInt: cellType] forKey: lineIDString];
return lineSize.height + actorSize.height + 200;
} else {
// return something here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With