我有一个包含很多行的 UITableView。 它就像 Accordion :http://docs.jquery.com/UI/Accordion 主细胞有子细胞,子细胞也有子细胞。所以这是一个三层的tableView。
好吧,当用户选择一个单元格时,它会展开(或折叠)带有行动画的子单元格。 但是我需要设置 tableView 和 scrollView 的新大小。
我用这个方法做了所有这些事情:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
问题: 当用户点击一个单元格,然后快速点击一个子单元格时,第二个动画不会完成,因此不会显示 2 级的子单元格。但大小已设置(考虑到已显示级别 2 的子单元格)。
实际上我是在浪费时间来处理这件事……但这真的很糟糕。
这是我的代码示例:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Checking with times (with 0,5 second interval in order to be sure that the previous animation is finished !)
// Setting tableView & scollView heights
[tableView beginUpdates];
if(position.isExpanded == YES)
[tableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationBottom];
else
[tableView reloadRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
[tableView endUpdates];
}
所以,我想 catch 这个动画的结尾。 或者,玩一种信号量(但我只有一个进程......) 有解决这个问题的想法吗?
请在您的回复中记住我是 iPhone 开发的新手。
谢谢。
最佳答案
动画由 CAAnimation
类的实例控制。此类支持方法 - (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag
,该方法将传递给此实例的委托(delegate)。此信息通常用于在完成时获得通知。
关于您的特殊要求,我会查看 UIView
类引用。有几个任务处理该 View 的动画——它是 UITableView
的基类。因此,任何对 UIView
有效的东西都应该对 TableView 有影响。
关于objective-c - UITableView,如何捕捉动画结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2378602/