【问题标题】:Hiding UITableViewCells when entering edit mode in UITableViewCell (similar to Contacts app)在 UITableViewCell 中进入编辑模式时隐藏 UITableViewCells(类似于联系人应用程序)
【发布时间】:2011-09-25 11:56:05
【问题描述】:

有谁知道在进入编辑模式时如何从分组的 UITableView 中隐藏一些单元格?我希望这些行在退出编辑模式时以动画效果隐藏,如联系人应用程序中所示。

如您所知,在通讯录编辑模式下,行数比切换回正常模式时多。我想知道切换是如何顺利完成的。

请注意,我的 UITableView 子类使用 IBOutlets 从同一个 nib 加载静态 UITableViewCells。

【问题讨论】:

    标签: ios uitableview contacts hidden


    【解决方案1】:

    仅针对删除或插入多组行的更新:

    [self.tableView beginUpdates];
    [self.tableView reloadRowsAtIndexPaths: ......];
    [self.tableView insertRowsAtIndexPaths: ......];
    [self.tableView removeRowsAtIndexPaths: ......];
    [self.tableView endUpdates];
    

    :D

    【讨论】:

    • 感谢 Enrico,事实上这就是我设法更改多行的方法:)
    【解决方案2】:

    当你设置 UITableView 的编辑模式时,你必须先更新你的数据源,然后插入/删除行。

    - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
        [super setEditing:editing animated:animated];
        [tableView setEditing:editing animated:animated];
    
        // populate this array with the NSIndexPath's of the rows you want to add/remove
        NSMutableArray *indexPaths = [NSMutableArray new];
    
        if(editing) [self.tableView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
        else [self.tableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
    
        [indexPaths release];
    }
    

    【讨论】:

    • 谢谢@Michael。一些澄清.. '更新您的数据源'您的意思是我在tableView:cellForRowAtIndexPath: 委托中执行if(myTableView.editing) 条件?此外,我还必须在tableView:numberOfRowsInSection:numberOfSectionsInTableView: 中执行相同的条件,因为我在编辑模式下的部分和行较少。对吗?
    • 好的,它通过准备 2 个不同的字典数据源(一个用于正常模式,另一个用于编辑模式)解决了这个问题,然后在 setEditing:animated: 调用中,我只需在这些字典数据源之间切换 tv 数据源。然后使用其他一些逻辑,我删除/插入您@Michael提到的行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-31
    • 1970-01-01
    相关资源
    最近更新 更多