带动画的UITableview reloaddata [英] UITableview reloaddata with animation

查看:89
本文介绍了带动画的UITableview reloaddata的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UItableview,它从数组和下拉列表中填充。
如果我选择任何一行下拉列表,数组将插入新值,tableview应重新加载。
如何使用新数组内容为tableview设置动画?提前谢谢

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];
 }


推荐答案

添加到正确答案,如果您想重新加载 UITableView 中的所有部分,您需要执行以下操作:

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.

这篇关于带动画的UITableview reloaddata的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆