UITableView不会显示删除按钮

时间:2016-11-22 07:09:30

标签: ios swift uitableview swift3 ios10

我已经实现了这些方法:

 func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool
  {
    return true
  }

  func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {

    if (editingStyle == UITableViewCellEditingStyle.delete) {
      showAlertToDeleteDevice()
    }
  }

并在其中设置断点,但没有回调这些函数。 -cellForRowAtIndexPath和-didSelectRowAtIndexPath函数工作正常,这意味着dataSource和Delegate连接都很好。

有什么问题?因为我没有通过滑动看到删除按钮。在同一时间,我看到我的其他表的删除按钮。

2 个答案:

答案 0 :(得分:1)

你使用了错误的功能。

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

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if (editingStyle == UITableViewCellEditingStyle.Delete) {
        // delete action
    }
}

答案 1 :(得分:1)

你必须实施

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]?