這是一個簡單的問題:爲什麼下面的代碼會導致「控制可能會達到非void函數結束」警告?在什麼情況下,兩個回報聲明中的一個不會被擊中?將else
塊之外的第二個return
聲明放在外面是更加標準的編碼習慣嗎?這確實使警告無效,但我很好奇它爲什麼存在。Xcode認爲控制可能會因if/else語句中的返回而達到非void函數的末尾
- (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;
}
}
代碼看起來腥反正:'kExtraCellType'看起來像一個常量,不是一個類型。 '[self cellIsGoingToContainExtraView]'看起來像返回一個BOOL,而不是'kExtraCellType'。如果沒有識別細胞的參數,它如何計算有意義的東西?你應該回顧Cocoa編碼風格的約定。 – 2013-03-06 13:32:57
看到我的答案也許它有幫助http://stackoverflow.com/a/39275095/1470374 – zest 2016-09-01 15:06:17