3

I want to add my sliderButton after the animation has ended but this doesn't work, it adds the button while the deletion of the section is being animated.

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

Is there a possibility I can call a method that does that for me when the animation ended?

Cosmin
  • 2,840
  • 5
  • 32
  • 50
  • add sliderButton with some animation so that after animation of deletion of the section is complete your button is added. – hchouhan02 Mar 07 '12 at 08:30

4 Answers4

7

I believe that wrapping your table update in animateWithDuration would work:

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

Other methods that I found suggested here on Stack Overflow did not work for me.

I used this technique at one time and tested it enough to verify that the completion block was called after I called the table's endUpdates method, but rewrote my code so I didn't need it any more before I had completely verified that the animation was actually finished.

David Hull
  • 1,255
  • 1
  • 14
  • 17
  • Using this method will skip the animating part of the animation and simply complete it instantly, even if you put in a longer duration like 1.0. – Rob Norback Sep 10 '16 at 19:23
6

You can find the answer here:

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

Hope it helps!

Community
  • 1
  • 1
Antonio MG
  • 20,382
  • 3
  • 43
  • 62
0

I have also not found the solution of this.I have to use performSelector:withObject:afterDelay: for getting my work done.

Manish Agrawal
  • 10,958
  • 6
  • 44
  • 76
0
[coursesTable deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];

after this the tableview again asks data from its datasource... so all the datasource methods including cellforRow is again called..

i suggest keeping a BOOL is Deleting.

so now do this

    [coursesTable beginUpdates];
        [coursesTable deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
        [coursesTable endUpdates];
Deleting = YES;

in cellForRow method

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


}
}
Shubhank
  • 21,721
  • 8
  • 65
  • 83