Я создал UITableView с 1 секцией и 3 строками в нем. Текст в каждой строке жестко запрограммирован, и мне нужно вызвать определенные действия, нажав каждую строку. Почему UITableView delegae метод 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