用下面的代碼,我得到了點擊的按鈕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