Search code examples
iosswiftuitableviewcontentoffset

UITableview contentoffset sometimes not working


I have the following code in the viewDidAppear:

        DispatchQueue.main.async {
        let bottomOffset = CGPoint(x: 0, y: self.tableView.contentSize.height - self.tableView.frame.size.height)
        //self.tableView.setContentOffset(bottomOffset, animated: false)
        self.tableView.contentOffset = bottomOffset
        }

And 85% of time it working well, but some times when I open this viewController tableview rows are on the top, not on the bottom. What's wrong?


Solution

  • For some reason, this worked for me:

    self.tableView.contentOffset.y = newPosition
    

    as opposed to

    self.tableView.setContentOffset(CGPoint(x: 0, y: newPosition))
    

    Apple did it again