UITableview reloaddata with animation

Iam having a UItableview that is populated from an array and a drop down list. If I select any row of the drop-down list, the array will be inserted with the new values, and the tableview should reload. How to animate table view with new array contents? thank you in advance

as if I want to show the line one by one. I tried this method

- (void)reloadRowsAtIndexPaths:(NSArray )indexPaths withRowAnimation:(UITableViewRowAnimation)animation { NSIndexPath rowToReload = [NSIndexPath indexPathForRow:[names count] inSection:0]; NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil]; [tableDetails reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone]; } 
+62
ios uitableview reloaddata
Jan 29 '13 at 6:28
source share
9 answers

To add the correct answer, if you want to reload all sections in a UITableView , you will need to do the following:

Objc

 NSRange range = NSMakeRange(0, [self numberOfSectionsInTableView:self.tableView]); NSIndexSet *sections = [NSIndexSet indexSetWithIndexesInRange:range]; [self.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationAutomatic]; 



Swift

 let range = NSMakeRange(0, self.tableView.numberOfSections) let sections = NSIndexSet(indexesIn: range) self.tableView.reloadSections(sections as IndexSet, with: .automatic) 

This will reload everything in the table view with animation. Like a boss.

+103
Jan 20 '14 at 16:45
source share

use this method

 [_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade]; 
+52
Jan 29 '13 at 6:43
source share

Swift 3

 UIView.transition(with: myTableView, duration: 1.0, options: .transitionCrossDissolve, animations: {self.myTableView.reloadData()}, completion: nil) 



Swift 2

 UIView.transitionWithView(myTableView, duration: 1.0, options: .TransitionCrossDissolve, animations: {self.myTableView.reloadData()}, completion: nil) 

I went with this in Swift

+37
Jul 14 '16 at 15:43
source share

You will first say that tableView is waiting for an update using beginUpdates . Then update the relevant sections (if your tableView has only one section, and then just skip zero for the section number). Here, where you specify the animation, you can play with it to get the desired effect. After that, you call endUpdates in the tableView. The typedef for UITableViewRowAnimation states:

 typedef enum { UITableViewRowAnimationFade, UITableViewRowAnimationRight, UITableViewRowAnimationLeft, UITableViewRowAnimationTop, UITableViewRowAnimationBottom, UITableViewRowAnimationNone, UITableViewRowAnimationMiddle, UITableViewRowAnimationAutomatic = 100 } UITableViewRowAnimation; 

Play to see which one you want. Even selecting UITableViewRowAnimationNone can sometimes have a good effect. Code update table below:

  [self.tableView beginUpdates]; [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone]; [self.tableView endUpdates]; 
+21
Jan 29 '13 at 6:53
source share

In Swift 3, you can simply add the following extension to the UITableView :

 extension UITableView { func reloadData(with animation: UITableView.RowAnimation) { reloadSections(IndexSet(integersIn: 0..<numberOfSections), with: animation) } } 
+16
Jan 06 '17 at 19:44
source share

you can use reloadSections:withRowAnimation: functions. Check out the UITableView Class Reference .

Check out reloadData with Animation , which already answered your question.

+5
Jan 29 '13 at 6:38
source share

The following method is supported by tableView for animation:

 - (void)reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0); 

Using:

 //Reload tableView with animation [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationRight]; 

Various types of animation are available:

 typedef NS_ENUM(NSInteger, UITableViewRowAnimation) { UITableViewRowAnimationFade, UITableViewRowAnimationRight, // slide in from right (or out to right) UITableViewRowAnimationLeft, UITableViewRowAnimationTop, UITableViewRowAnimationBottom, UITableViewRowAnimationNone, // available in iOS 3.0 UITableViewRowAnimationMiddle, // available in iOS 3.2. attempts to keep cell centered in the space it will/did occupy UITableViewRowAnimationAutomatic = 100 // available in iOS 5.0. chooses an appropriate animation style for you }; 

Hope this helps!

+3
Dec 24 '13 at 14:11
source share

I tried this and my Table is Animated with smooth animation

// Put this code where you want to reload the table view

 dispatch_async(dispatch_get_main_queue(), ^{ [UIView transitionWithView:<"TableName"> duration:0.1f options:UIViewAnimationOptionTransitionFlipFromRight animations:^(void) { [<"TableName"> reloadData]; } completion:NULL]; }); 
+3
Feb 24 '16 at 6:02
source share

Try animation on transition. Changing view while reloading UITableView

 [UIView transitionWithView:_yourTableView duration:0.40f options:UIViewAnimationOptionTransitionCrossDissolve animations:^(void) {[_yourTableView reloadData];} completion:nil]; 
+2
Jan 22 '16 at 19:48
source share



All Articles