UITableView scroll to new row only when at the end of table.

UITableView scroll to new row only when at the end of table.

Category : Objective-C , XCode

[tldr: code at bottom]

Let me explain the title. I wanted to have a UITableView that adds new rows, and also scrolls to the new row that just got inserted.

But theres the annoying that if you’re viewing older rows in the middle of the tableview, you don’t want the tableview to scroll you away from that when it adds a new row.

I created this method that only scrolls to the newly added row, when you’re at the end of the tableview, so if you’re viewing some data in the middle of the tableview, it won’t scroll you away from it. This works with both single-section and multi-section tableviews as well. Explanation in the code comments. It’s pretty simple actually.

It’s also useful for anyone looking for how to make the table scroll when adding a new row, regardless of where you are in the tableview.

Enjoy, this is coming straight from a new game project I’m working on.

As always, comments and questions are welcome.

Tell your friends what you found!
The following two tabs change content below.
Game Designer, Programmer, Lover of all things retro. I've been a programmer for about 8 years. Got into game development part time 6 years ago and haven't been able to put it down.

Latest posts by Justin Fletcher (see all)

Liked it? Take a second to support Justin Fletcher on Patreon!

About Author

Justin Fletcher

Game Designer, Programmer, Lover of all things retro. I've been a programmer for about 8 years. Got into game development part time 6 years ago and haven't been able to put it down.

Leave a Reply

Show Some Love

Support The Weekly Coder on Patreon!

WeeklyCoderTV

Recent Popular Info

About:
This channel is all about coding. We will mostly post tutorials on making games with Unity 5 and above. Other posts will include tutorials on specific game mechanics and whatever else we feel like talking about.

Don't be shy.. If you have a question, leave a comment. If you you'd like to see a specific tutorial feel free to request it. If we think its worthwhile, then we may just do it.

Please don't forget to click the like button and remember to subscribe. Feel free to support our channel and the awesome content we create.

Total subscribers:
767

Total uploads:
71

Total upload views:
89.1 thousand

Follow me on Twitter

Subscribe

RSS Feed

Blog Authors