swift - 没有在 UITableViewController 中调用 DidSelectRowAt
问题描述
我知道对此的典型解决方案是将 的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
}
}
解决方案
我发现了这个问题。我不小心将 更改tableView
selection
为no selection
. 我的错。这不是代码。
推荐阅读
- vba - MS Visio 中的 VBA - 突出显示选定形状的连接器
- java - 为什么插入符号“^”不适用于 Java+Selenium+Eclipse?
- firebase - Firebase OnAuthStateChanged for Phone Auth 即使在 iOS 上也会触发
- node.js - firebase deploy --only hosting 给出错误:HTTP 错误:410,未知错误
- c - C 中的函数指针是如何工作的?- 具体例子
- python - Selenium (Python):getAttribute('value') 无法从文本输入中获取文本
- react-google-maps - react-google-maps:如何在父组件中使用 fitBounds API
- r - 为什么我的 R 箱线图中的变量不能反映我的实际数据?
- javascript - Chrome 中的 ES6 模块
- c++ - 在测试中使用部分初始化的对象