Cannot animate smoothly a TableView to new cells inserted at the bottom

I have an Swift application that generates information every few seconds and adds it to a ManagedObjectContext.

I have a tableview that implements the NSFetchedResultsControllerDelegate protocol displaying the new values in the screen.

The values always come one by one and they are always inserted at the bottom of the table.

The cells have variable size.

What I need is keep scrolling smoothy to the new inserted cell like it happens in a messaging application.

I have the following code:

func controllerWillChangeContent(controller: NSFetchedResultsController) {

func controller(controller: NSFetchedResultsController, didChangeObject anObject: AnyObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
    self.tableView!.insertRowsAtIndexPaths([newIndexPath!], withRowAnimation: .None)
    self.insertedIndexPath = newIndexPath

func controllerDidChangeContent(controller: NSFetchedResultsController) {
    self.tableView!.scrollToRowAtIndexPath(self.insertedIndexPath!, atScrollPosition: .None, animated: animated)

The code works fine, but when there are many rows in the table the animation of the scrolling jumps up and down in every new rows inserted.

Dows anybody know how to make this animation running smooth to the new row?




I have found the solution to my problem. The issue is that I was using auto resizing.

self.tableView!.rowHeight = UITableViewAutomaticDimension
self.tableView!.estimatedRowHeight = 150

The size of my table cells could be very different and the auto resizing always starts sizing the cell to the estimated value. Before adding the new cell the table scrolls automatically to a position calculated based on the estimation. Since the average size could be so variable, the estimated place where the table is scrolled is always wrong which move the scroll up and down like crazy. To solve the problem I set the method:

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat

I calculate the size right before I set the content of the view. In this way the table calculate the scroll based on the real size of the cells. I hope it helps. GA

Need Your Help

Zooming to center on a map in Google Maps API V3

javascript google-maps google-maps-api-3

I'm new to using google maps and am trying to find out how to restrict the zoom function so that it does not zoom anywhere except of the center of the map and not zoom to the mouse point. Basically...

Possible ways to identify RewriteRule when both files are in the same folder?

php apache .htaccess

Ok this maybe sound like the worst question on stackoverflow but here it is.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.