UITableView indexPathForCell: return nil in iOS10 with Xcode8 (Swift2.3)

UITableView indexPathForCell: return nil in iOS10 with Xcode8 (Swift2.3)

在相同条件下,iOS9 很好,但无法获取 iOS10 中单元格的索引路径。

self.tableView.indexPathForCell(单元格): nil

现在,我发现该单元格不在 iOS10 的 visibleCells 中。 就是这个问题。

在iOS10中,cellForRowAtIndexPath被提前调用。 所以,那么,indexPathForCellnil,因为单元格不可见。

我找到的解决方案是这样的。

if #available(iOS 10, *) {
    indexPath = self.tableView?.indexPathForRowAtPoint(cell.center)
}