[UITableView]beginUpdates和endUpdates - 实现UITableView的动画块
2016-04-06 22:04
411 查看
UITableView的修改,删除,选择
需要对UITableView进行一系列的动作操作。这样,我们就会用到
[tableView beginUpdates]; if (newCount<=0) { [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]withRowAnimation:UITableViewRowAnimationLeft]; } [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationLeft]; [tableView endUpdates];
向上面一段代码,就是动态删除UITableView 的UITableViewCell的操作。
因为,如果我们的UITableView是分组的时候,我们如果删除某个分组的最后一条记录时,相应的分组也将被删除。所以,必须保证UITableView的分组,和cell同时被删除。
所以,就需要使用beginUpdates方法和endUpdates方法,将要做的删除操作“包”起来!
beginUpdates方法和endUpdates方法是什么呢?
这两个方法,是配合起来使用的,标记了一个tableView的动画块。分别代表动画的开始开始和结束。
两者成对出现,可以嵌套使用。
一般,在添加,删除,选择 tableView中使用,并实现动画效果。
在动画块内,不建议使用reloadData方法,如果使用,会影响动画。
一般什么时候使用这么一个动画块呢?
一般在UITableView执行以下情况时使用,用来协调UITableView的动画效果:1. 删除行
2. 插入行
3. 删除分组
4. 插入分组
插入指定的行,
在执行该方法时,会对数据源进行访问(分组数据和行数据),并更新可见行。所以,在调用该方法前,应该先更新数据源
插入分组到制定位置
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation
插入一个特定的分组。如果,指定的位置上已经存在了分组,那么原来的分组向后移动一个位置。
- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
删除制定位置的分组
删除一个制定位置的分组,其后面的分组向前移动一个位置。- (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation
移动分组
移动原来的分组从一个位置移动到一个新的位置。如果,新位置上若存在某个分组,那这某个分组将会向上(下)移动到临近一个位置。该方法,没有动画参数。会直接移动。并且一次只能移动一个分组。- (void)moveSection:(NSInteger)section toSection:(NSInteger)newSection
相关文章推荐
- leetcode 51. N-Queens
- UIAlertController(UIActionSheet、UIAlertView)
- DOM元素querySelectorAll和querySelector
- 用java生成GUID
- quick组件模块的使用以及简单案例
- LinkedBlockingQueue源码分析
- 87. Repeated DNA Sequences
- 2015山东省第六届ACM省赛 Lowest Unique Price
- 安装StarUML 及使用时序图(Sequence Diagram)和用例图(use case diagram)
- android studio新建module不生成build文件夹
- reproducible-research-quiz2
- iOS开发学习笔记——导航控制器1(UINavigationController)
- Calling View methods on another thread than the UI thread.错误
- Android 刷新UI界面,线程间通讯方法总结,Android 自学之路
- UESTC 548 Cow IDs (二进制的排列 组合数 STL)
- IOS 开发-UI初级 (一)
- UITextfield的一些属性
- a mirror of Android build ENV setup flow
- ANDROID 中UID与PID的作用与区别
- iOS开发中关于多线程的问题(NSOperationQueue,NSThread,GCD)