UITableView setContentOffset not working after beginUpdates called

190 views Asked by At

I have this function to move the tableview up whenever the keyboard shows:

@objc func keyboardWillShow(notification: Notification) {
        DispatchQueue.main.async {
            let screenScaleFactor: CGFloat = 375 / UIScreen.main.bounds.size.height
            self.currentOffset = self.formTableView.contentOffset
            let maxY = self.formTableView.contentOffset.y
            let offset = CGPoint.init(x: 0, y: maxY + 260.0 * screenScaleFactor)
            self.formTableView.setContentOffset(offset, animated: false)
            
        }

    }

And this code for expanding cell when selected in didSelectRowAt:

case eventForm.rsvpLabelCellIndexPath:
    if eventForm.isRSVPPickerShown {
        eventForm.isRSVPPickerShown = false
    } else {
        eventForm.isRSVPPickerShown = true
    }
    tableView.beginUpdates()
    tableView.endUpdates()

But after calling beginUpdates() and endUpdates() setContentOffset stops working. It works normally when beginUpdates() is not called. It also works again if the tableView is scrolled by dragging.

I have tried to set the contentOffset to the saved value before and after beginUpdates() is called.

This is essentially the same issue tableView.setContentOffset(_, animated:) do not work after beginUpdates(). However I am using DispatchQueue.main.async and it is still not working.

Any suggestions?

0

There are 0 answers