Ios 对于UITableViewCell中的嵌套UITableView,未调用didSelectRowAt indexPath:
我有一个Ios 对于UITableViewCell中的嵌套UITableView,未调用didSelectRowAt indexPath:,ios,swift,uitableview,Ios,Swift,Uitableview,我有一个UITableView嵌套在另一个UITableView中。 在嵌套的tableView中,当用户点击某个单元格时,该单元格会高亮显示,但不会调用委托方法didSelectRowAt indexPath: 正在调用其他委托方法,例如willDisplay cell:forRowAt indexath:或scrollViewDidScroll(quo;:)。这说明代理等连接正确 在同一个应用程序的另一个部分中,我使用了相同类型的结构,UITableView在另一个UITableView中,
UITableView
嵌套在另一个UITableView
中。
在嵌套的tableView中,当用户点击某个单元格时,该单元格会高亮显示,但不会调用委托方法didSelectRowAt indexPath:
正在调用其他委托方法,例如willDisplay cell:forRowAt indexath:
或scrollViewDidScroll(quo;:)
。这说明代理等连接正确
在同一个应用程序的另一个部分中,我使用了相同类型的结构,UITableView
在另一个UITableView
中,它工作得很好。
我对两者进行了广泛的比较,到目前为止我还没有发现差异,也不知道为什么一个应该工作,另一个不应该
请参阅嵌套的UITableViewCell
的实现。
如果控制台能记录“触摸检测到”这一行就好了。
它会记录行“滚动”和“将显示单元格”
最终解决方案非常简单。 我为外部
UITableView
设置了一个uitagesturerecognizer
。
我把它放在那里,以便在敲击时关闭键盘。
卸下UITapgestureRecognitor
后,它开始正常工作
我完全忽略了这一点,但现在问题解决了 如果点击并按住几秒钟,它会被触发吗?视图调试器会显示什么?因为,也许在现实中,你正在点击
UITableViewCell
而不是嵌入的UITableViewB
的UITableViewCell
。@Glenn:你的意思是想看看外部UITableViewCell的didSelectRowAt indexPath:是否被触发?@GIJOW不,它根本没有被触发..是的,其他UITableViewCell
的didSelectRowAt
委托方法。同时检查视图的层次结构。
import UIKit
class TestTableViewCell: UITableViewCell {
}
extension TestTableViewCell: UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return tableView.dequeueReusableCell(withIdentifier: "FileCell")!
}
}
extension TestTableViewCell: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("touch detected")
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
print("will display cell")
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
print("scrolling")
}
}