Search code examples
iosswifttableviewslide

Sliding a tableview in iOS


How do I slide all the content in the table view and update the table view with new content, i am working on a project just like google drive IOS app, where when u click on a folder, the old content slides to left and the new content slides in from the right, does anybody have any idea about this? Any help will be greatly appreciated, thanks!!!


Solution

  • tableView.beginUpdates()
        tableView.insertRowsAtIndexPaths(toAdd, withRowAnimation: animateLeft ? .Right : .Left)
        tableView.deleteRowsAtIndexPaths(toDelete, withRowAnimation: animateLeft ? .Left : .Right)
    tableView.endUpdates()
    

    If you are going to remove all of the data then the toDelete variable is an array of indexPaths 0 through currentContent.count. The toAdd variable is an array of indexPaths 0 through newContent.count. animateLeft is a boolean of which way you want to animate your content