Swift - 覆盖编辑按钮功能

时间:2015-08-02 14:09:48

标签: ios swift uitableview

我有一个UITableView,它预装了一个编辑按钮(UITableView.editButtonItem())。按下时,它会切换到" Done",并且当您要删除它们时,您会在条目旁边看到那些红色减号。

我想将自定义代码附加到按钮上,这样当您点击它时,您就不会获得红色减号。在编辑模式下,每当您单击某个条目时,它都会显示一个UIActionSheet或UIAlertController以允许您进行更改。

所以,我想覆盖编辑按钮,以便点击时:

  • 红色减去"删除"图标不会显示
  • 细胞变得可选择。

我尝试过创建一个自定义的UIBarButtonItem,但这是一个可怕的解决方法。我认为我想要的是可行的,我只是不确定如何。

2 个答案:

答案 0 :(得分:0)

delegate使用UIViewController,并对该按钮的事件制作自定义代码。如果它位于每一行,则必须在tap action代期间从代码中附加cell。 我自己会考虑custom class

答案 1 :(得分:0)

我已经找到了要调用的方法:

// The following two functions remove the red minus sign
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
    return UITableViewCellEditingStyle.None
}

override func tableView(tableView: UITableView, shouldIndentWhileEditingRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return false
}

// The following property allows you to select cells while in editing mode
    self.tableView.allowsSelectionDuringEditing = true