Bra*_*mas 4 objective-c uitableview ios10
在 iOS 10 中,会抛出这个新警告。
当方法无法确定要返回的适当单元格(例如异常)时,从 cellForRowAtIndexPath 返回的适当方法是什么?
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView == self.selectedContentTableView) {
        // make cell...
        return cell;
    }
    else if(tableView == self.recipientTableView) {
        // make cell...
        return cell;
    }
    else {
        NSLog(@"Some exception message for unexpected tableView");
        return nil; // ??? what now instead
    }
}
如果这种情况是不应发生的编程错误,则适当的操作是终止程序并显示错误消息,以便检测到并修复编程错误:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(tableView == self.selectedContentTableView) {
        // make cell...
        return cell;
    }
    else if(tableView == self.recipientTableView) {
        // make cell...
        return cell;
    }
    else {
        NSLog(@"Some exception message for unexpected tableView");
        abort();
    }
}
该abort()函数被标记为__attribute__((noreturn)),因此编译器不会抱怨缺少返回值。
| 归档时间: | 
 | 
| 查看次数: | 2929 次 | 
| 最近记录: |