[英]UITableView not scrollable after scrollToRow
I have a table with number of rows. 我有一个表,行数。 I would like to pre-scroll table after it's load and it's not so hard, but I have a problem. 我想在表加载后对其进行预滚动,这并不难,但是我有一个问题。 Table become non-scrollable after scrollToRow
execution. 在执行scrollToRow
之后,表变得不可滚动。
Here is my code scroll function: 这是我的代码滚动功能:
func scrollToValue() {
var scrollPosition: Int = 30
let indexPath = IndexPath(row: scrollPosition, section: 0)
tableView.scrollToRow(at: indexPath, at: .middle, animated: true)
}
and I execute it in viewDidLayoutSubviews
: 我在viewDidLayoutSubviews
执行它:
override func viewDidLayoutSubviews() {
scrollToValue()
}
Here is what I have executed this code and try to move table top or bottom: table moves back to 15.0
value at the middle after my interaction, but I would like to scroll to any other position top and bottom without rollback. 这是我执行此代码并尝试将表的顶部或底部移动的内容:交互后,表在中间移回15.0
值,但是我想滚动到顶部和底部的任何其他位置而无需回滚。 Even though if I choose false for animation scrollToRow(at: indexPath, at: .middle, animated: false)
I can't move cells at all. 即使我为动画scrollToRow(at: indexPath, at: .middle, animated: false)
选择false ,我也无法移动单元格。 I can see scroll indicator at the right but cells are frozen. 我可以在右侧看到滚动指示器,但是单元格被冻结。
Remove scroll action from layoutSubviews as tableView is still not loaded and try this 从tableSub移除滚动动作,因为tableView仍未加载,请尝试此操作
override func viewDidAppear() {
scrollToValue()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.