Swift tableView 滚动到行为我的 tableview 的内容偏移值提供了错误的值
Swift tableView scroll to row gives a wrong value for the content Offset value of my tableview
在我的应用程序中,我有一个表格视图,其中显示了大约 400 种产品。我面临的问题是,像这样以编程方式滚动到一个部分的开头:
@objc func CategoryPress(_ button: UIButton) {
let indexPath = NSIndexPath(item: 0, section: button.tag)
tableView.scrollToRow(at: indexPath as IndexPath, at: UITableViewScrollPosition.top, animated: false)
}
我的 tableView.contentOffset.y 得到了一个错误的值,在我再次到达表格视图的顶部之前,该值一直不正确。 仅当滚动到远离我的起始位置的位置时才会出现此问题。
手动滚动时我没有遇到这个问题,我的所有值都是准确的。
我试图在按下按钮时滚动到特定的 y,但我没有找到执行此操作的方法。
任何获得特定职位的解决方案或替代方案将不胜感激。
我找到了一个可行的替代方案:
@obj func CategoryPress(_ button: UIButton) {
let indexPath = NSIndexPath(item: 0, section: button.tag)
var offset: CGPoint = tableView.contentOffset
offset.y = CGFloat(Ycoordinates[indexPath.section])
tableView.setContentOffset(offset, animated: true)
}
在我的应用程序中,我有一个表格视图,其中显示了大约 400 种产品。我面临的问题是,像这样以编程方式滚动到一个部分的开头:
@objc func CategoryPress(_ button: UIButton) {
let indexPath = NSIndexPath(item: 0, section: button.tag)
tableView.scrollToRow(at: indexPath as IndexPath, at: UITableViewScrollPosition.top, animated: false)
}
我的 tableView.contentOffset.y 得到了一个错误的值,在我再次到达表格视图的顶部之前,该值一直不正确。 仅当滚动到远离我的起始位置的位置时才会出现此问题。
手动滚动时我没有遇到这个问题,我的所有值都是准确的。
我试图在按下按钮时滚动到特定的 y,但我没有找到执行此操作的方法。
任何获得特定职位的解决方案或替代方案将不胜感激。
我找到了一个可行的替代方案:
@obj func CategoryPress(_ button: UIButton) {
let indexPath = NSIndexPath(item: 0, section: button.tag)
var offset: CGPoint = tableView.contentOffset
offset.y = CGFloat(Ycoordinates[indexPath.section])
tableView.setContentOffset(offset, animated: true)
}