Я знаю, что типичным решением этого является присвоение delegate
из tableView
для UIViewController
.Проблема здесь в том, что это на самом деле UITableViewController
.С учетом сказанного вот в чем проблема.
У меня есть CategoriesTVC
, который наследуется от SwipeTVC
(суперкласс SwipeTVC
- UITableViewController
).Все работало нормально, и вдруг это прекратилось.Понятия не имею, почему.
Я поставил точку останова на методе didSelectRowAt
, и он никогда не выполняется.Вот код:
class CategoryTVC: SwipeTVC {
let realm = try! Realm()
var categories: Results<Category>?
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goToItems" {
let destination = segue.destination as! ToDoListTVC
if let indexPath = tableView.indexPathForSelectedRow {
destination.selectedCategory = categories?[indexPath.row]
}
}
}
// MARK: - Table view data source
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return categories?.count ?? 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = super.tableView(tableView, cellForRowAt: indexPath)
cell.textLabel?.text = categories?[indexPath.row].name ?? "No categories added yet"
cell.backgroundColor = UIColor(hexString: categories?[indexPath.row].backgroundColor ?? "DA7553")
return cell
}
// MARK: Table View Delegate methods
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
super.tableView(tableView, didSelectRowAt: indexPath)
performSegue(withIdentifier: "goToItems", sender: self)
}
}
class SwipeTVC: UITableViewController, SwipeTableViewCellDelegate {
var cell: UITableViewCell?
// MARK:- Table View DataSource
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! SwipeTableViewCell
cell.delegate = self
return cell
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
guard orientation == .right else { return nil }
let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
self.updateModel(at: indexPath)
}
deleteAction.image = UIImage(named: "delete")
return [deleteAction]
}
func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeOptions {
var options = SwipeOptions()
options.expansionStyle = .destructive
return options
}
// MARK:- Swipe Actions
func updateModel(at indexPath: IndexPath) {
// overridden in VC
}
}