加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – reloadSections的麻烦:withRowAnimation动画

发布时间:2020-12-14 18:10:59 所属栏目:百科 来源:网络整理
导读:我有一个UITableView有两个部分(顶部和底部).当在顶部(第0部分)“检查”项目时,我将它们移动到底部(第1部分),反之亦然.除了动画,一切都很好. 我正在使用以下内容,但行动作缓慢 – 我在其他应用程序中看到了更好的结果.我希望从顶部开始的行能够干净地动画到
我有一个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.

解决方法

问题解决了.请参阅已编辑的回复.代码应该是:

// 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];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读