How to keep UITableView contentoffset after calling -reloadData

前端 未结 13 1370
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 02:43
CGPoint offset = [_table contentOffset];
[_table reloadData];
[_table setContentOffset:offset animated:NO];    //unuseful

//    __block UITableView *tableBlock = _t         


        
13条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 03:10

    @Skywalker's answer showed best workaround for estimated height of cells problem. But sometimes problem lyes in a different place.
    Sometimes the problem lyes in contentInsets of table view. If you make reload data while tableView is not visible on the screen you can face with wrong offset after the table view appears on the screen.
    It happens because UIViewController can control insets if his scrollView when the scrollView is appearing to allow lying of scrollView below transparent navigationBar and statusBar.
    I've faced with this behaviour in iOS 9.1

提交回复
热议问题