Home Scroll to last message on collection view is not working properly
Reply: 0

Scroll to last message on collection view is not working properly

Edwjonn
1#
Edwjonn Published in 2018-01-13 00:17:13Z

I have a CollectionView that has an input accesory view at the bottom containing a text field and other elements. The app works like a messaging app: you write something and then you send it, at which point the message is added to the collection view.

The problem is that, with the code I've implemented, the "auto scroll" stars working when there is a certain number of messages (items in the collection view), 16-18 is the amount of items you need to add before the auto-scroll stars to work. This is the code I've implemented so far:

DispatchQueue.main.async {
    self.collectionView?.reloadData()
    self.inputTextField.text = ""

    if self.messages.count > 0 {
       let indexpath = IndexPath(item: self.messages.count - 1, section: 0)
       self.collectionView?.scrollToItem(at: indexpath, at: .bottom, animated: true)
    }
}

That code is in the textFieldShouldReturn method.

This is what i get when i put a breakpoint in the line "self.collectionView?..."

Thanks in advanced for the help!!!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311814 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO