xcode reloadSections:withRowAnimation 动画问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10593493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Trouble with reloadSections:withRowAnimation animation
提问by mySilmaril
I have a UITableView with two sections (a top section and a bottom section). When items are "checked off" in the top section (section 0), I'm moving them them to the bottom section (section 1) and vice versa. Everything is working great save for the animation.
我有一个包含两个部分(顶部和底部)的 UITableView。当项目在顶部(第 0 部分)中被“选中”时,我会将它们移到底部(第 1 部分),反之亦然。除了动画之外,一切都很好。
I'm using the following, but the row movement is sluggish - I've seen better results in other apps. I'd like the rows from the top section to animate cleanly to the bottom section ... and the rows from the bottom section to animate cleanly to the top section when they are checked or unchecked.
我正在使用以下内容,但行移动缓慢 - 我在其他应用程序中看到了更好的结果。我希望顶部的行可以清晰地动画到底部……而底部的行在选中或取消选中时可以干净地动画到顶部。
// set the guests arrival status and use animation
[guestList beginUpdates];
if (!guest.didArrive) {
[guest setDidArrive:YES];
[guestList reloadSections:sectionIndexSet withRowAnimation:UITableViewRowAnimationBottom];
} else {
[guest setDidArrive:NO];
[guestList reloadSections:sectionIndexSet withRowAnimation:UITableViewRowAnimationTop];
}
[guestList endUpdates];
[guestList reloadData];
How should I code this for nice smooth animation?
我应该如何编码以获得漂亮的流畅动画?
Edit:
编辑:
I found the problem. The could should be written this way instead:
我发现了问题。应该这样写:
//NSIndexSet *sectionIndexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, 1)];
// set the guests arrival status and use animation
[guestList beginUpdates];
if (!guest.didArrive) {
[guest setDidArrive:YES];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationBottom];
} else {
[guest setDidArrive:NO];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationTop];
}
[guestList endUpdates];
[guestList reloadData];
Note the first line that I commented out. I neglected to add this originally. As you can see, I was using a poorly constructed NSIndexSet.
注意我注释掉的第一行。我最初忽略了添加这个。如您所见,我使用了一个构造不佳的 NSIndexSet。
回答by mySilmaril
Problem solved. Please see edited response. Code should be:
问题解决了。请参阅编辑后的回复。代码应该是:
// set the guests arrival status and use animation
[guestList beginUpdates];
if (!guest.didArrive) {
[guest setDidArrive:YES];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationBottom];
} else {
[guest setDidArrive:NO];
[guestList reloadSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationTop];
}
[guestList endUpdates];
[guestList reloadData];
回答by nicolasthenoz
Why do you need to reloadData of your guestList at the end of the function ? You are already reloading the sections you want... Try removing that and check again.
为什么需要在函数结束时重新加载 guestList 的数据?您已经在重新加载您想要的部分...尝试删除它并再次检查。