If you work on something like an chat app, you may need to use the
UITableView in a way where data is filled from bottom to top. An example of this is a chat detail screen, where you want the
UITableView to show the latest messages at the bottom when loaded, new messages are added to the bottom and immediately shown and older messages are loaded on top when the user scrolls to the top of the
There are multiple ways to achieve this, each with some advantages and disadvantages.
The first simplest idea that comes to mind is using the
UITableView as is and just scrolling it when necessary:
- Scroll to bottom when the initial messages are loaded
- Scroll to bottom when a new message is added
- When older messages are about to be added to the top, remember the position, add the older messages, scroll back to that position
The first two situations are easy to accomplish, but the last one is not. I could not find a way to make it works without a visible scrolling effect.
UITableView 180 degrees
Another solution is to rotate the
UITableView by 180 degrees; rotating it upside down. Of course you have to also “flip” your data source but that is trivial to achieve. The advantage is that you do not have to do any scrolling when new messages are added to the bottom (which is the top of the rotated
UITableView) and if you use batch updates instead of reload neither when older messages are loaded.