Scroll to the bottom of the tableView before view is on screen

Hello,

I’m currently building an app which has a chat integrated.

I want the default behavior of iMessage & WhatsApp where you tap on one conversation, you land automatically to the bottom of the tableView/collectionView.

I don’t want the user to notice the scrolling to bottom of the tableView/collectionView.

Thank you in advance.

Take a look at the scrollToRow method. Apple docs are here.

Something like the following in your viewWillAppear method?
self.tableView.scrollToRow(at: xxxx, at: .bottom , animated: false)
The xxxx would be the indexPath for your last cell.

I’m not where I can test this, but it should get you started.

Have fun!

Hey thank you @rcasey,

Yeah, this is the current implementation I have, but I notice that even when placing this code in the viewWillAppear, the user still get a glimpse of the tableView scrolling to the bottom and this is the effect I want to avoid.

Have finally a solution.

Flipping the tableView with the transform property on viewWillAppear do the trick.
tableView.transform = CGAffineTransform(scaleX: 1, y: -1)

But the cells will be upside-down so we need to do it for them as well:
cell.transform = CGAffineTransform(scaleX: 1, y: -1)

Thank you.

Cheers

This topic was automatically closed after 166 days. New replies are no longer allowed.