用下面的代码,我得到了点击的按钮TableView中indexPath:IndexPath斯威夫特的TableView点击列
@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
。
宁在对的cellForRowAtIndexPath分配indexpath.row到Button.tag然后使用tableView.indexPathForRow获得该单元格上面的方法你提到cpu很贵。 –
看来你想要的是'indexPath.section' –
谢谢@Sam_M !!!! – user1469734