我有一个带有静态单元格和节标题的 TableViewController。我尝试调用 indexPath.row
但是,它们不是唯一的。例如
TableView:
- Header 1
- Cell1 indexPath = 0
- Header 2
- Cell2 indexPath = 0
- Cell3 indexPath = 1
- Cell4 indexPath = 2
获取行唯一标识符的正确方法是什么?
因为使用这个使 2 个单元格具有相同的 indexPath
override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
print(indexPath.row)
if indexPath.row != 0 {
return indexPath
}
return nil
}
最佳答案
您似乎忽略了 indexPath.section
。部分和行的组合唯一地定义了索引路径。一行在其部分内是唯一的。
关于ios - IndexPath.row 不是静态单元格唯一的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36896074/