1セクションと3行のUITableViewを作成しました。各行のテキストはハードコードされており、各行をタップして特定のアクションを呼び出す必要があります。 次のコードでUITableViewデリバリメソッドfunc tableView(_ tableView:UITableView、didSelectRowAt indexPath:IndexPath)が呼び出されないのはなぜですか?UITableViewの行アクションが呼び出されない
@IBOutlet weak var tbvSetting: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
tbvSetting.reloadData()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")! as UITableViewCell
switch indexPath.row {
case 0:
cell.textLabel?.text = "Countries"
case 1:
cell.textLabel?.text = "Managers"
case 2:
cell.textLabel?.text = "Customers"
default:
break
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print(indexPath.row)
}
ヒントありがとうございました。
あなたは 'UITableViewDelegate'を実装しましたか?呼び出される関数は 'UITableViewDataSource'で呼び出されます。両方を実装する必要があります。 – Dima
はい、これは私のクラス宣言クラスです。vcSettings:UIViewController、UITableViewDelegate、UITableViewDataSource、メソッドfunc tableView(_ tableView:UITableView、cellForRowAt indexPath:IndexPath) - > UITableViewCellは正常に動作します。 – Dawy