UITableView contentOffSet is not working properly

前端 未结 15 1752
滥情空心
滥情空心 2020-12-14 01:48

In viewWillAppear, I have added UISearchBar as my headerview of UITableView. When view loads, I hides UISearchbar under <

相关标签:
15条回答
  • 2020-12-14 02:10

    You need to hide the search bar by yourself when you scroll the table. So don't put it as a UITableView header. You could hide it by setting its height to zero. That way if your table view is set to auto resize, it will expand.

    0 讨论(0)
  • 2020-12-14 02:10
    self.tableView.contentInset = UIEdgeInsetsMake(self.navigationController.navigationBar.frame.size.height -80, 0, 0, 0);
    
    0 讨论(0)
  • 2020-12-14 02:11

    In my case the problem was that I called

     [_myGreatTableView reloadData];
    

    before getting the _tableView.contentOffset.y. This always returned '0'.

    So I switched the order of these methods and now it works.

    This is quite a strange behavior in my opinion, because offset returned 0 but the UI still kept the scroll position of the table.

    0 讨论(0)
  • 2020-12-14 02:12

    I fixed it with layoutIfNeeded()

        self.articlesCollectionView.reloadData()
        self.articlesCollectionView.layoutIfNeeded()
        self.articlesCollectionView.setContentOffset(CGPoint(x: 0, y: 40), animated: false)
    
    0 讨论(0)
  • 2020-12-14 02:12

    In iOS 7/8/9 simple self.automaticallyAdjustsScrollViewInsets = NO; solved the problem in my case

    0 讨论(0)
  • 2020-12-14 02:13

    The problem is auto masking. Select your table and make sure you have selected all the lines, as in the image below.

    enter image description here

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