有一个reloadData的UITableView动画时改变 [英] Have a reloadData for a UITableView animate when changing

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

问题描述

我有一个UITableView有两种模式。当我们在模式之间切换时,我有不同数量的部分和每个部分的单元格。



这是我尝试的代码,但它不做任何事情:

  CGContextRef context = UIGraphicsGetCurrentContext(); 
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.5];

[self.tableView reloadData];
[UIView commitAnimations];关于我如何做到这一点的任何想法?


h2_lin>解决方案

其实很简单:

  [_ tableView reloadSections:[NSIndexSet indexSetWithIndex :0] withRowAnimation:UITableViewRowAnimationFade]; 

从文件:


调用此方法会导致表视图向其数据源请求指定节的
个新单元格。表视图动画了新单元格的
插入,因为它会对旧单元格进行动画处理。



I have a UITableView that has two modes. When we switch between the modes I have a different number of sections and cells per section. Ideally, it would do some cool animation when the table grows or shrinks.

Here is the code I tried, but it doesn't do anything:

CGContextRef context = UIGraphicsGetCurrentContext(); 
[UIView beginAnimations:nil context:context]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDuration:0.5]; 

[self.tableView reloadData];
[UIView commitAnimations];

Any thoughts on how I could do this?

解决方案

Actually, it's very simple:

[_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];

From the documentation:

Calling this method causes the table view to ask its data source for new cells for the specified sections. The table view animates the insertion of new cells in as it animates the old cells out.

这篇关于有一个reloadData的UITableView动画时改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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