section使用時のtableViewの応用例
任意のCellのタップ時に動作を条件分岐させたい
swift
import UIKit
class TableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("selected Section is: \(indexPath.section)")
print("selected Row is: \(indexPath.row)")
if indexPath.section == 1 && indexPath.row == 2 {
// do something...
}
これで任意のCellのタップ時に動作の条件分岐ができるようになりました。