Skip to content

Instantly share code, notes, and snippets.

@KC-218
Created March 29, 2018 08:47
Show Gist options
  • Save KC-218/a80c995583064974d9f228b47c2c5ef8 to your computer and use it in GitHub Desktop.
Save KC-218/a80c995583064974d9f228b47c2c5ef8 to your computer and use it in GitHub Desktop.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CustomCell = CustomCell()
cell.button.addTarget(self, action: #selector(buttonClicked(sender:)), for: .touchUpInside)
}
func buttonClicked(sender: UIButton) {
let tapLocation = sender.convert(CGPoint.zero, to: tableView) //取得按鈕位置
let tapIndexPath = self.tableView.indexPathForRow(at: tapLocation) //這個位置位於哪個indexPath
print(tapIndexPath.row)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment