Ios Tableview-等待单元格被删除,然后再添加新单元格

Ios Tableview-等待单元格被删除,然后再添加新单元格,ios,objective-c,animation,uitableview,Ios,Objective C,Animation,Uitableview,我有一个表视图,如果您选择一行,它会在该行下面添加一个选择器。但如果选择了另一行,它将隐藏第一个选择器(使用选择器删除该行),然后添加一个新选择器 现在我的问题是,如何在添加新行之前等待移除动画完成 这就是我添加新行的方式。它在didSelectRow方法中 NSIndexPath *selectedIndex = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section]; pickerInserted

我有一个表视图,如果您选择一行,它会在该行下面添加一个选择器。但如果选择了另一行,它将隐藏第一个选择器(使用选择器删除该行),然后添加一个新选择器

现在我的问题是,如何在添加新行之前等待移除动画完成

这就是我添加新行的方式。它在didSelectRow方法中

NSIndexPath *selectedIndex = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section];
pickerInsertedAtIndexPath = selectedIndex;
NSArray *indexes = @[selectedIndex];
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationMiddle];
[tableView endUpdates];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationMiddle];
[tableView endUpdates];
这就是我删除一行的方式。这在willSelectRow方法中

NSIndexPath *selectedIndex = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section];
pickerInsertedAtIndexPath = selectedIndex;
NSArray *indexes = @[selectedIndex];
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationMiddle];
[tableView endUpdates];
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:indexes withRowAnimation:UITableViewRowAnimationMiddle];
[tableView endUpdates];

不幸的是,没有回调表视图动画何时结束。在添加新选择器之前,您必须等待您选择的时间间隔。

不确定这是否符合您的场景,但您可以使用:

一个
UITableViewDelegate
回调,它将在从
UITableView
中删除单元格时通知您