在[self.tableView endUpdates]结束后调用方法

时间:2012-03-07 08:22:03

标签: iphone uitableview animation ios5

我想在动画结束后添加我的sliderButton,但这不起作用,它会在删除部分动画时添加按钮。

    [coursesTable beginUpdates];
    [coursesTable deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
    [coursesTable endUpdates];
    [self.view addSubview:sliderButton];

有可能我可以在动画结束时调用一个为我做的方法吗?

4 个答案:

答案 0 :(得分:7)

我认为将表格更新包装在animateWithDuration中会有效:

[UIView animateWithDuration:0.0 animations:^{
    [coursesTable beginUpdates];
    …
    [coursesTable endUpdates];
} completion:^(BOOL finished) {
    // Code to run when table updates are complete.
}];

我在Stack Overflow上找到的其他方法对我不起作用。

我一次使用这种技术并进行了足够的测试以验证在调用表的endUpdates方法后调用了完成块,但重写了我的代码,所以在我完全验证之前我不再需要它了动画实际上已经完成了。

答案 1 :(得分:6)

你可以在这里找到答案:

How to detect that animation has ended on UITableView beginUpdates/endUpdates?

希望它有所帮助!

答案 2 :(得分:0)

我也没有找到解决方案。我必须使用performSelector:withObject:afterDelay:来完成我的工作。

答案 3 :(得分:0)

[coursesTable deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];

之后,tableview再次向其数据源询问数据...所以再次调用包括cellforRow在内的所有数据源方法。

我建议保持BOOL正在删除。

现在就这样做

    [coursesTable beginUpdates];
        [coursesTable deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
        [coursesTable endUpdates];
Deleting = YES;
在cellForRow方法中

{
if (index path.row == lastrow ) // last rowcell is reached
if(Deleting)
{
//tableView has reloaded.
    [self.view addSubview:sliderButton];
    Deleting = NO;;


}
}
相关问题