Video of the problem : https://drive.google.com/file/d/1aWNqyg8fraFC0NSr47K3WkvlGTbBWkQH/view?usp=sharing
I have a UITableView with .grouped style. Some of my cells contain a TextView that updates its height constraint as the user type text. Each time the TextView updates the height constraint, the cell calls a delegate in implemented in the my custom tableView : cell.delegate.needsSizeReload, so tableView may update its layout like that :
func needsSizeReload(_ sender:UITableViewCell)
{
UIView.performWithoutAnimation {
beginUpdates()
endUpdates()
}
// adjustFirstResponder() see if the cell at keyboardIndexPath is partially under the keyboard frame
// if it's the case, it scrolls to it so the bottom of the cell goes right above the keyboard
if(self.keyboardIndexPath != nil)
{
self.adjustFirstResponder()
}
}
There are 2 problems, that you can see the video attached :
- When I type a
for a 9th line (and not other lines), the contentOffset jumps and the bottom of the TextView is not anymore right above the keyboard. I verified it's not a side effect of self.adjustFirstResponder()
because the jump occurs right before it, and still happens if I remove it and scroll myself each time the user goes under the keyboard.
- When I scroll to top after that, the scrolling jumps too (we can't see it very well on the video because FPS has been reduced from original)
I know there's a lot of question like this one on StackOverflow, but I assure I came across all of them during many hours and none of the answer worked. Especially, these famous solutions on SO didn't work for me :
(1) Switching from rowHeight = automatic
to fixed size with heightForRowAt indexPath
: doesn't work
(2) Keeping manual height mode (I saw it's better anyway for performance), and returning estimatedHeight
so it's equal to what returns heightForRowAt
: doesn't work
(3) contentInsetAdjustmentBehavior = .never
doesn't work either
The only thing that works for both problems is having a .plain tableView style instead of a .grouped style. But I want to keep my sections divided..
Any idea ? Is that a UIKit known bug ? These jump problems are really annoying, and I saw on SO I'm definitely not the only one..
question from:
https://stackoverflow.com/questions/65873536/uitableview-bug-contentoffset-jumps-randomly-after-resizing-textview-cells-on 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…