简体   繁体   English

UITableView区分要删除的滑动和多行选择

[英]UITableView differentiate swipe to delete and multiple rows selection

I'm working with a UITableView, and want to support both the standard edit tools provided by Apple. 我正在使用UITableView,并且希望支持Apple提供的两种标准编辑工具。 So far, I can swipe on a cell to show the "delete" button, and tap an "edit" button on the top right to enter multi-rows editing mode. 到目前为止,我可以在一个单元格上滑动以显示“删除”按钮,然后点击右上角的“编辑”按钮以进入多行编辑模式。 That's working fine. 很好

Problem is, I want my tableView to act just like as the mail app does, which is "do nothing else than show the delete button" when entering editing mode with the swipe gesture, and "show a trashcan button (anywhere)" when entering multi-rows editing mode. 问题是,我希望我的tableView像邮件应用程序一样工作,即在使用滑动手势进入编辑模式时“除了显示删除按钮外什么都不做”,而在输入时“显示垃圾桶按钮(随处显示)”多行编辑模式。 I can't figure out how I can know which editing mode I'm in... 我不知道如何知道自己处于哪种编辑模式...

For example, I added the setEditing method, in which I hide the tab bar (just to check the behavior of my table): 例如,我添加了setEditing方法,其中隐藏了标签栏(仅用于检查表的行为):

-(void)setEditing:(BOOL)editing animated:(BOOL)animated 
{

    self.tableView.allowsMultipleSelectionDuringEditing = editing;
    [super setEditing:editing animated:animated];

    if (editing) {

        self.tabBarController.tabBar.hidden = YES;

    } else {

        self.tabBarController.tabBar.hidden = NO;
    }

}

Right now, when I swipe on a cell, or when I hit the edit button, the tab bar is hidden, and goes back to normal afterwards. 现在,当我在某个单元格上滑动时,或者当我按下“编辑”按钮时,选项卡栏将被隐藏,然后恢复正常。 I would like to hide it only when I hit the edit button. 我只想在单击编辑按钮时才将其隐藏。

Where and how should I do that ? 我在哪里和应该怎么做?

Thanks. 谢谢。

Why not handing the sender over to the editing method, like this? 为什么不像这样将发件人移交给编辑方法呢?

-(void)setEditing:(BOOL)editing animated:(BOOL)animated sender:(id)sender
{

    self.tableView.allowsMultipleSelectionDuringEditing = editing;
    [super setEditing:editing animated:animated];
    if (editing && [sender isKindOfClass:[UIButton class]]) 
    {
        self.tabBarController.tabBar.hidden = YES;
    } 
    else 
    {
        self.tabBarController.tabBar.hidden = NO;
    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM