UITableViewControllerでのセルタップ時の処理に関して
初めまして、閲覧ありがとうございます。
最近Swiftの勉強を始め、UITableViewControllerを使ってみようと思ったのですが、表示した個別のセルをタッチした際のイベント処理が上手くできずに困っております。
参考処理を検索しても多くがViewControllerを画面として進めているものが多く、TableViewControllerでの実装方法を詳しく知りたく質問いたしました。
自分が調べている感想ではUITableViewControllerならfunc tableViewが自動的に実行されるイメージがあったので、「実行されました」というログが表示されると思っていたのですが、何か不足な処理等があるのでしょうか?
どなたか助けて頂ければと思いますので宜しくお願い致します。
該当のソースコード
Swift3.1
import UIKit class Page04: UITableViewController { let array:[String] = ["Page02","Page03","Page04"] override func viewDidLoad() { super.viewDidLoad() self.tableView.estimatedRowHeight = 100 self.tableView.rowHeight = UITableViewAutomaticDimension self.setNeedsStatusBarAppearanceUpdate() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } override var prefersStatusBarHidden: Bool { return true } override func numberOfSections(in tableView: UITableView) -> Int { return 1 } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return array.count } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "Id_Page04_Cell", for: indexPath) cell.textLabel?.text = array[indexPath.row] // indexPath.rowはセルの番号 return cell } override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { return 100 } func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { //UITableViewDelegate: セルがタップされたときの処理 print("実行されました") } }