这是一个简单的问题:为什么以下代码会导致“控件可能到达非无效函数结束”警告?在什么情况下两个 return 语句之一不会被命中?return
将第二条语句放在else
块之外会是更标准的编码实践吗?这确实使警告静音,但我很好奇它为什么存在。
- (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;
}
}