[英]UITableView didSelectRowAt does not register
I have a custom UITableView
in a ViewController
. 我在
ViewController
有一个自定义UITableView
。 My custom table has custom UITableViewCells
. 我的自定义表具有自定义
UITableViewCells
。 This is the code inside my ViewController
: 这是我的
ViewController
的代码:
ViewDidLoad
: ViewDidLoad
:
self.firstListTable.dataSource = self
self.firstListTable.delegate = self
self.firstListTable.register(UINib(nibName: "firstQueueCell", bundle: Bundle.main), forCellReuseIdentifier: "firstCell")
self.searchListTable.dataSource = self
self.searchListTable.delegate = self
self.searchListTable.allowsSelection = true
self.searchListTable.register(UINib(nibName: "SearchCell", bundle: Bundle.main), forCellReuseIdentifier: "SearchCell")
self.searchListTable.separatorStyle = .none
UITableViewFunctions
: UITableViewFunctions
:
func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
if tableView == self.searchListTable {
print("hello")
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
print("hello")
}
didHighlightRowAt
works but didSelectRowAt
does not. didHighlightRowAt
有效,但didSelectRowAt
不起作用。
I tried this: didSelectRowAtIndexPath: not being called 我试过这个: didSelectRowAtIndexPath:不被调用
What other causes could there be? 还有什么其他原因?
Thanks! 谢谢!
If you want didHighlightRowAt
and didSelectRowAt
both response, you can overwrite your method didHighlightRowAt
like this : 如果您都想要
didHighlightRowAt
和didSelectRowAt
这两个响应,则可以这样覆盖方法didHighlightRowAt
:
func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
if tableView == self.searchListTable {
print("hello")
// this is my OC code ,change it to your swift code
[tableView selectRowAtIndexPath:IndexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}
You can understand this as didHighlightRowAt
method and didSelectRowAt
method have conflicts, if you want both method response, you must make some special treatment. 您可以将其理解为
didHighlightRowAt
方法和didSelectRowAt
方法有冲突,如果您想同时响应两个方法,则必须进行一些特殊处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.