IndexPath.row对于静态单元格不是唯一的

sen*_*nty 0 uitableview didselectrowatindexpath nsindexpath ios swift

我有一个带静态单元格和节头的TableViewController.indexPath.row然而,我试着打电话,它们并不是唯一的......例如

TableView:
- Header 1
  - Cell1  indexPath = 0
- Header 2
  - Cell2  indexPath = 0
  - Cell3  indexPath = 1
  - Cell4  indexPath = 2
Run Code Online (Sandbox Code Playgroud)

获取行的唯一标识符的正确方法是什么?


因为使用这个使2个单元格具有相同的indexPath

override func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? {
   print(indexPath.row)

   if indexPath.row != 0 {
     return indexPath
   }

   return nil
}
Run Code Online (Sandbox Code Playgroud)

rma*_*ddy 6

你似乎无视indexPath.section.section和row的组合唯一地定义了索引路径.一行在其部分中是唯一的.