UITableView scrollToRowAtIndexPath scrolls to wrong offset with estimatedRowHeight on iOS 7

后端 未结 9 1861
轮回少年
轮回少年 2021-02-12 12:46

I am using the estimatedRowHeight method from UITableView in iOS 7, which works perfectly for fast loading of a UITableView with 5000 rows of variable heights.

相关标签:
9条回答
  • 2021-02-12 13:30

    Mine was wrong because the "atScrollPosition" was set to UITableViewScrollPositionNone - change it to UITableViewScrollPositionMiddle and it should work fine

    0 讨论(0)
  • 2021-02-12 13:33

    This solved my problem

    let oldContentSize = tableView.contentSize
    tableView.scrollToRow(at: indexPath, at: .top, animated: true)
    // Called again when tableView contentSize change
    if !tableView.contentSize.equalTo(oldContentSize) {
        tableView.scrollToRow(at: indexPath, at: .top, animated: true)
    }
    
    0 讨论(0)
  • 2021-02-12 13:34

    Unfortunately this issue is to be expected when using estimatedRowHeight in your code with such a low value. When you scrollToRowAtIndexPath it does not actively calculating the correct size as you go. The underlying cause is, if you scrolled from Section 1 to Section 2, it could feasibly calculate the correct position on the fly and the estimatedRowHeight of the cells if it was a relatively new device. Any older devices would be brought to their knees, and even any new ones would be as well if you had to process 5000 cells, for example.

    A maybe-solution to your problem could be to increase the estimatedRowHeight constant so the device doesn't have to do as much work.

    0 讨论(0)
提交回复
热议问题