swift - 两个并排的 UITableView 同时滚动
问题描述
我有两个UITableView
并排在一起UIViewController
。我希望这些 tableViews 同时滚动。这里我用过contentOffset
。但问题是,当我尝试通过触摸右 tableView 滚动表格视图时,它正在工作。但是,当我尝试通过触摸左侧 tableView 来滚动表格视图时,它不起作用。如何通过触摸任何 tableView 一次滚动它们?
这是我的代码 -
func scrollViewDidScroll(_ scrollView: UIScrollView) {
tableViewTwo.contentSize.height = tableViewOne.contentSize.height
tableViewOne.contentOffset = tableViewTwo.contentOffset
}
解决方案
您可以尝试以下方法:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == tableView1 {
tableView2.contentOffset = scrollView.contentOffset
tableView2.contentSize.height = scrollView.contentSize.height
} else {
tableView1.contentOffset = scrollView.contentOffset
tableView1.contentSize.height = scrollView.contentSize.height
}
}
推荐阅读
- php - 从后到前发送错误消息(php + html)
- php - 如何用pdo根据store一一拉取
- c# - 如何比较两个标签并相应地更新gridview?ASP.NET 网格视图
- javascript - 以不规则长度向字符串添加分隔符 - Javascript
- c++ - 使用模板将类型发送到函数中
- python - 卷积神经网络中的空间信息是什么?
- c# - 如何在 c# 中为特定 IP 和进程创建 TCP 网桥/TCP Sniffer?
- linux - 将 STDERR 输出重定向到文件
- tcp - 使用wireshark完成了多少次TCP握手和拆除?
- asp.net-core - 在 asp.net 核心中的 HttpClient web api 调用中出现未处理的异常,但无法理解问题