0

I have a view controller with a table view and a NSArray that represent my model. In viewDidLoad I fill the array with objects and then I call [tableView reloadData] to fill the table view. The result is that the table view get filled in one chunk, and I don't like it.
I want it to slide down, like I was adding one cell after a nother.
Is this possible?

If I try to do something like this:

    [self.tableView beginUpdates];

    for (int i=0; i < sortedPersons.count; i++) {
        Person *personInfo = [sortedPersons objectAtIndex:i];
        [self.myMainModelArr addObject:personInfo];

        NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
        [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
    }

    [self.tableView endUpdates];

I get Invalid table view update error

4

1 回答 1

2

使用 UITableView 时,您可以使用一些委托函数来帮助解决此问题。当你要向 tableView 添加一些东西时,一定要使用:

[tableView beginUpdates];

然后在插入时可以使用委托方法:

- (void)insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation

然后在完成添加时,请务必使用:

[tableView endUpdates];

所有这些函数都可以从UITableView 类参考中查看

这里有一小段代码:UITableView add cell Animation

于 2012-04-25T00:18:43.817 回答