Search code examples
iosswiftuicollectionviewuicollectionviewlayout

How to set data from bottom to top while chat using firebase


I am working on firebase chat app, i designed my layout and implemented chat module successfully but, the problem is when i send text message it works fine and set text data to bottom of the collectionView but when i close my app and open it again the setting of text data mismatch and the last message comes upward.

I tried all stack overflow questions and others try's but nothing happens any change. enter image description here can't reverse data


Solution

  • Populate your array in reverse order, Because when you inserting data into array you insert last message at zero index of array, so populate array in reverse order on collection view e.g Array.reverse or you can insert data in reverse order into you array, e.g insert last message on last index of array. If you've any issue let me know.