gpt4 book ai didi

swift - IndexPath Swift TableView 单击的列

转载 作者:行者123 更新时间:2023-11-28 06:13:43 40 4
gpt4 key购买 nike

通过下面的代码,我得到了 tableview 中被点击按钮的 indexPath:

@IBAction func btnClick(_ sender: UIButton) {
let hitPoint = sender.convert(CGPoint.zero, to: self.tableView)
if let indexPath = self.tableView.indexPathForRow(at: hitPoint){
print(indexPath)
print(indexPath.row)
}
}

第一次打印是 [3, 0] 当我点击第 3 行时,我得到了 0,但我需要另一个值。本例中的 3

最佳答案

indexPath 返回 [section, row]。

如果你想访问部分(你称为列的东西),使用 indexPath.section

关于swift - IndexPath Swift TableView 单击的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45733711/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com