UITableview reloaddata with animation

2019-01-21 03:28发布

Iam having a UItableview which is populated from array and a drop down list. If i select any row of drop down list the array will be inserted with new values and tableview should reload. How to animate the tableview with new array contents ? thanks in advance

animation like i want to show the row 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];
 }

9条回答
倾城 Initia
2楼-- · 2019-01-21 03:45

I have tried this and my Table is Animated with smooth animation

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

dispatch_async(dispatch_get_main_queue(), ^{
    [UIView transitionWithView:<"TableName"> 
                      duration:0.1f 
                       options:UIViewAnimationOptionTransitionFlipFromRight 
                    animations:^(void) {
                        [<"TableName"> reloadData];
                    } completion:NULL];        
});
查看更多
放我归山
3楼-- · 2019-01-21 03:48

Try Animating while Transition Change of a view while reloading UITableView

[UIView transitionWithView:_yourTableView 
                  duration:0.40f 
                   options:UIViewAnimationOptionTransitionCrossDissolve 
                animations:^(void) {[_yourTableView reloadData];}  
                completion:nil];
查看更多
等我变得足够好
4楼-- · 2019-01-21 03:55

You first tell the tableView to expect updates with beginUpdates. Then update the relevant sections (if your tableView has only one section then just pass zero for the section number). Here's where you specify the animation - you can play around with it to get the effect that you want. After that you call endUpdates on the tableView. The typedef for UITableViewRowAnimation specifies:

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

Play around to see which one you want. Even selecting UITableViewRowAnimationNone can have a nice effect sometimes. Table update code below:

    [self.tableView beginUpdates];
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];
查看更多
登录 后发表回答