【发布时间】:2012-05-15 02:37:01
【问题描述】:
我有一个包含两个部分(顶部和底部)的 UITableView。当项目在顶部(第 0 部分)被“选中”时,我将它们移动到底部(第 1 部分),反之亦然。除了动画,一切都很好。
我正在使用以下内容,但行移动缓慢 - 我在其他应用中看到了更好的结果。我希望顶部的行在选中或未选中时干净地动画到底部......并且底部的行在选中或未选中时干净地动画到顶部。
// 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];
我应该如何编写代码以获得流畅的动画?
编辑:
我发现了问题。应该这样写:
//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];
注意我注释掉的第一行。我最初忽略了添加这个。如您所见,我使用的是构造不佳的 NSIndexSet。
【问题讨论】:
标签: ios xcode uitableview reloaddata