开发者

How to reload all table cells after adding or removing a cell?

After I add or remove a cell, only the cell I added or removed is reloaded. I need all of my cells to reload after a new cell is added or removed.

I know about [self.tableView reloadData], but if I call that right after adding or removing a cell, it cuts the cell add/remove animation.

I actual开发者_开发知识库ly have come up with a way to solve this problem, but it's somewhat hacktacular and I figured there might be a better way. This is what I do now:

[self.tableView deleteRowsAtIndexPaths:row_to_delete withRowAnimation:UITableViewRowAnimationRight];

double delayInSeconds = .25;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self.tableView reloadData];
});


Try to reload table with delay.

After deletion,

[self performSelector:@selector(reloadTableview) withObject:nil afterDelay:0.35];

-(void) reloadTableview {
     [self.YourTableView reloadData];
}


Call beginUpdates if you want subsequent insertions, deletion, and selection operations (for example, cellForRowAtIndexPath: and indexPathsForVisibleRows) to be animated simultaneously. This group of methods must conclude with an invocation of endUpdates. These method pairs can be nested. If you do not make the insertion, deletion, and selection calls inside this block, table attributes such as row count might become invalid. You should not call reloadData within the group; if you call this method within the group, you will need to perform any animations yourself.

[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:row_to_delete withRowAnimation:UITableViewRowAnimationRight];
[self.tableView endUpdates];


Maybe you can use this tableView method :

- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation

inside a block :

[tv beginUpdates];

// delete and reloadRows    

[tv endUpdates];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜