ios - IndexPath.row 不是静态单元格唯一的

标签 ios swift uitableview didselectrowatindexpath nsindexpath

我有一个带有静态单元格和节标题的 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/

相关文章:

android - GCM - iOS 客户端控制推送通知?

iphone - 如何将按钮添加到 QLPreviewController

Swift 以编程方式向标签添加约束

swift - 为什么RXSwift的bindTo方法失败

ios - Alamofire:如何在 UITableView 中顺序下载 zip 文件

ios - 快速高效的数据加载

ios - 删除应用程序不应删除文档目录

ios - 如何从子JSON中获取数据

ios - 按下 UICollectionViewCell 内的按钮会影响其他按钮

ios - 如何为 TableView 创建 NSIndexPath