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条回答
爷的心禁止访问
2楼-- · 2019-01-21 03:37

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

extension UITableView {
    func reloadData(with animation: UITableViewRowAnimation) {
        reloadSections(IndexSet(integersIn: 0..<numberOfSections), with: animation)
    }
}
查看更多
祖国的老花朵
3楼-- · 2019-01-21 03:39

use this method,

[_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
查看更多
我想做一个坏孩纸
4楼-- · 2019-01-21 03:39

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

查看更多
我想做一个坏孩纸
5楼-- · 2019-01-21 03:40

To add to the correct answer, if you want to reload all sections in your 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 an animation. Like a boss.

查看更多
等我变得足够好
6楼-- · 2019-01-21 03:40

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

Check this reloadData with Animation which already answered your question.

查看更多
对你真心纯属浪费
7楼-- · 2019-01-21 03:41

Below method is supported by tableView for animation :

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

Usage :

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

Different types of animation available are :

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 might help!

查看更多
登录 后发表回答