【问题标题】:IOS: Allow SwipeToDelete But Don't Show Editing Button in TableviewIOS:允许 SwipeToDelete 但不在 Tableview 中显示编辑按钮
【发布时间】:2017-08-23 15:19:10
【问题描述】:

对于表格视图,我希望允许 SwipeToDelete 并且我还希望允许人们在能够上下移动行的意义上编辑表格视图。但是,在上下移动行时,我想抑制删除按钮,因为它有点分散注意力。

有没有办法在编辑模式下抑制删除按钮时允许滑动删除?

我正在尝试以下委托,但它没有完成工作:

    - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView  editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Detemine if it's in editing mode
        if (self.editing)
        {
NSLog(@"thinks it is editing");
            return UITableViewCellEditingStyleDelete; //enable when editing mode is on
        }
        else {
NSLog(@"thinks editing mode is off");
          //  return UITableViewCellEditingStyleDelete;
           return UITableViewCellEditingStyleNone;
        }
    }

当我将 else 设置为删除时,它允许滑动删除但也显示删除按钮。

当我将 else 设置为 None 时,它​​不允许滑动删除,但会抑制删除按钮。

self.editing 无法胜任。

【问题讨论】:

    标签: ios tableview delete-row


    【解决方案1】:

    你应该为editingStyle...返回UITableViewCellEditingStyleNone(以避免在编辑模式下在单元格左侧显示绿色的+或红色的-按钮。然后你可以从canEdit...返回YES表示仍然可以通过滑动编辑单元格(即删除):

    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
        return UITableViewCellEditingStyleNone; 
    }
    
    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
        return YES;
    }
    

    (可选)您还可以使用以下方法来防止在编辑模式期间单元格左侧出现多余的空间(否则-+ 按钮会出现):

    - (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
        return NO;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-03
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      相关资源
      最近更新 更多