Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created March 8, 2021 03:07
Show Gist options
  • Save KrauserHuang/6076ded22b390ca6f682f05d53e5a771 to your computer and use it in GitHub Desktop.
Save KrauserHuang/6076ded22b390ca6f682f05d53e5a771 to your computer and use it in GitHub Desktop.
extension ViewController: UITableViewDelegate {
// 點選cell後執行的動作
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// 設置取消點選cell後的動畫
tableView.deselectRow(at: indexPath, animated: true)
let name = info[indexPath.section][indexPath.row]
print("選擇的是\(name)")
}
/*
點選 Accessory 按鈕後執行的動作
必須設置 cell 的 accessoryType
設置為 .DisclosureIndicator (向右箭頭)之外都會觸發
*/
func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
let name = info[indexPath.section][indexPath.row]
print("按下的是\(name)的detail")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment