在单元格中获取 indexPath.row

皮埃尔弗兰克

当我点击我的按钮时,我尝试在单元格中获取 indexPath.row:

@IBAction func cellPlayButtonPressed(_ sender: Any) {
    let cell = (sender as AnyObject).superview??.superview as? UITableViewCell
    let indexPath = runnerTableView.indexPath(for: cell!)
    print(indexPath)
}

当我按下按钮时出现此错误:

致命错误:在解开 Optional 值时意外发现 nil

我已经尝试了在 Stack Overflow 上找到的所有内容,但没有任何效果。

让我知道错误在哪里!谢谢 :)

最好的开发商

只需复制给定的扩展名

extension UITableView {    
func indexPath(forItem: AnyObject) -> IndexPath? {
    let itemPosition: CGPoint = forItem.convert(CGPoint.zero, to: self)
    return self.indexPathForRow(at: itemPosition)
}}

用:

@IBAction func cellPlayButtonPressed(_ sender: Any) {
    if let indexPath = runnerTableView.indexPath(forItem: sender) {
        print(indexPath)
    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

轻按单元格中的UIImageView时如何获取indexpath.row?

来自分类Dev

关于表视图单元格indexpath.row

来自分类Dev

获取嵌入在UITableViewCell中的UITable的单元格的indexPath

来自分类Dev

表视图单元格中的UIGestureRecognizer获取indexPath始终返回最后一个单元格的indexPath

来自分类Dev

如何将拖动的单元格的indexPath.row传递给函数?(迅速)

来自分类Dev

基于indexPath.row的自定义表单元格操作不起作用?

来自分类Dev

UICollectionViewCell不在indexpath.row == 0上绘制单元格

来自分类Dev

快速表格视图单元格不允许我使用 indexPath.row

来自分类Dev

在UICollectionView中重新加载indexPath.row

来自分类Dev

如何获取位于UICollectionView中心的单元格的indexPath

来自分类Dev

使用自定义单元格获取UITableViewCell indexPath

来自分类Dev

快速获取collectionView中心的单元格的indexPath?

来自分类Dev

iOS:UICollectionview,如何通过indexPath获取单元格的contentoffset

来自分类Dev

如何从委托的收集视图单元格中获取indexPath项?

来自分类Dev

在单元格创建/出队期间获取 tableViewCell 文件中 tableView 的 indexPath

来自分类Dev

静态UITableViewCell中indexPath处的单元格重复

来自分类Dev

如何知道单元格SWIFT的indexPath

来自分类Dev

通过TableViewCell Parse中的UIButton从indexPath.row传递PFObjects

来自分类Dev

在按钮功能Swift中访问indexPath.row

来自分类Dev

iOS:UICollectionview,如何通过它的indexPath获取单元格的contentoffset

来自分类Dev

如何在单个单元格公式中获取每个ROW的MAX值的总和?

来自分类Dev

单击 UITableView 中的标签时返回的 tablew 视图单元格中的 IndexPath 是错误的

来自分类Dev

在indexpath的行单元格仅被调用一次

来自分类Dev

给定UITableViewCell的indexPath,加载该特定单元格

来自分类Dev

Swift:UICollectionView选择单元格indexPath问题

来自分类Dev

如何快速获得选定单元格的IndexPath

来自分类Dev

为什么我的UISearchDisplayController访问非法的单元格/ indexPath?

来自分类Dev

如何确定已轻按的开关的单元格的indexPath?

来自分类Dev

Xcode UICollectionView如何通过indexpath禁用某些单元格

Related 相关文章

  1. 1

    轻按单元格中的UIImageView时如何获取indexpath.row?

  2. 2

    关于表视图单元格indexpath.row

  3. 3

    获取嵌入在UITableViewCell中的UITable的单元格的indexPath

  4. 4

    表视图单元格中的UIGestureRecognizer获取indexPath始终返回最后一个单元格的indexPath

  5. 5

    如何将拖动的单元格的indexPath.row传递给函数?(迅速)

  6. 6

    基于indexPath.row的自定义表单元格操作不起作用?

  7. 7

    UICollectionViewCell不在indexpath.row == 0上绘制单元格

  8. 8

    快速表格视图单元格不允许我使用 indexPath.row

  9. 9

    在UICollectionView中重新加载indexPath.row

  10. 10

    如何获取位于UICollectionView中心的单元格的indexPath

  11. 11

    使用自定义单元格获取UITableViewCell indexPath

  12. 12

    快速获取collectionView中心的单元格的indexPath?

  13. 13

    iOS:UICollectionview,如何通过indexPath获取单元格的contentoffset

  14. 14

    如何从委托的收集视图单元格中获取indexPath项?

  15. 15

    在单元格创建/出队期间获取 tableViewCell 文件中 tableView 的 indexPath

  16. 16

    静态UITableViewCell中indexPath处的单元格重复

  17. 17

    如何知道单元格SWIFT的indexPath

  18. 18

    通过TableViewCell Parse中的UIButton从indexPath.row传递PFObjects

  19. 19

    在按钮功能Swift中访问indexPath.row

  20. 20

    iOS:UICollectionview,如何通过它的indexPath获取单元格的contentoffset

  21. 21

    如何在单个单元格公式中获取每个ROW的MAX值的总和?

  22. 22

    单击 UITableView 中的标签时返回的 tablew 视图单元格中的 IndexPath 是错误的

  23. 23

    在indexpath的行单元格仅被调用一次

  24. 24

    给定UITableViewCell的indexPath,加载该特定单元格

  25. 25

    Swift:UICollectionView选择单元格indexPath问题

  26. 26

    如何快速获得选定单元格的IndexPath

  27. 27

    为什么我的UISearchDisplayController访问非法的单元格/ indexPath?

  28. 28

    如何确定已轻按的开关的单元格的indexPath?

  29. 29

    Xcode UICollectionView如何通过indexpath禁用某些单元格

热门标签

归档