UITableView动画头痛 [英] UITableView Animation Headache

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

问题描述

NSIndexPath* updatedPath = [NSIndexPath indexPathForRow: 0 inSection: 0]; 
NSIndexPath* updatedPath2 = [NSIndexPath indexPathForRow: 1 inSection: 0]; 
NSArray* updatedPaths = [NSArray arrayWithObjects:updatedPath, updatedPath2, nil]; 
[self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];

以上代码有效且动画效果。问题是我有很多数据,我不想硬编码行索引。因为我的表中只有一个部分可以是0.如何动态生成NSIndexPath对象的NSArray?

The above code works and it animates. The problem is that I have lot of data and I don't want to hard-code the row indexes. Since I have only one section in my table section can be 0. How can I dynamically generate NSArray of NSIndexPath objects?

或者有更简单的方法来为表视图设置动画。当用户单击表视图顶部的选项卡时,我的表视图中的所有行都会更改。

Or is there an easier way to animate the table view. All the rows in my table view change when the user clicks the tab on top of the table view.

推荐答案

生成数组索引路径,你可以循环:

To generate the array of index paths, you could just loop:

    NSMutableArray *updatedPaths = [NSMutableArray array];
    for (NSNumber *row in someArray) {
        NSIndexPath *updatedPath = [NSIndexPath indexPathForRow:[row intValue] inSection:0];
        [updatedPaths addObject:updatedPath];
    }
    [self.mySexyTableView reloadRowsAtIndexPaths:updatedPaths withRowAnimation:UITableViewRowAnimationTop];

如果你重新加载TableView中的所有数据,为什么不调用reloadData方法?

If you reload all data in your TableView, why not just call the reloadData method?

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

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