Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
394 views
in Technique[技术] by (71.8m points)

iphone - How can I tell When a UITableView animation has finished?

How can I tell when [UITableView setEditing:YES animated:YES] has completed?

I don't want to give any context, because I want to avoid anybody giving me workarounds, which do not interest me.

What I want is to call the above, then have a separate function called when the animation is completed.


I am edited the post to give context and some workarounds. Originally I setEditing and immediately reload the table data.

[tableView setEditing:YES animated:YES];
[tableView reloadData];

The problem is that the table reloads before the animation begins, and so the animation is never seen.

Here are some various workarounds:

[tableView setEditing:YES animated:YES];
[self performSelector:@selector(ReloadTable) withObject:nil afterDelay:1.0];

This works but if I get the delay incorrect then it will look bad. So I need to know what the delay is, which I can figure out, but we are not gauranteed that the delay will always be the same.

isEditing = YES;
[tableView reloadData];
[tableView setEditing:YES animated:YES];

This could work, but the table behaves differently depending on if we are in editing mode. So I have to use my own isEditing variable instead of the standard UITableView.editing. I would rather not have to create a new boolean isEditing variable.

[tableView setEditing:YES animated:YES];
[tableView insertRowsAtIndexPaths:path withRowAnimation:UITableViewRowAnimationTop];

This almost works well but in editing mode the first row should have the UITableViewCellEditingStyleInsert, while the other rows get UITableViewCellEditingStyleDelete. And with the above code the editing style gets set BEFORE the row is added. Therefore the second row ends up with UITableViewCellEditingStyleInsert.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
[CATransaction begin];
[CATransaction setCompletionBlock: ^{
    // your animation has finished
}];
[tableView setEditing:YES animated:YES];
[CATransaction commit];

Note that setCompletionBlock must be on the top.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...