UITableViewCell滑动不显示删除按钮

时间:2015-10-08 18:42:57

标签: ios swift uitableview swipe

我目前正在开发一个UITableViewController演示,它的工作方式与我希望它的工作方式一致。

当我在一行向左滑动时,我唯一没有得到的是删除删除按钮。

按钮的“空格”以及删除功能都在那里,但红色矩形按钮和文本“删除”都没有出现。

这发生在模拟器和设备上。

当然,我已经实现了“edititingStyleForRowAtIndexPath”

override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
    switch indexPath.section{
    case SectionConstants.MODEL_DATA_SECTION: return UITableViewCellEditingStyle.Delete
    case SectionConstants.NEW_DATA_SECTION: return UITableViewCellEditingStyle.Insert
    default: return UITableViewCellEditingStyle.None
    }
}

和'commitEditingStyle'与此无关,因为它是在触摸删除按钮后触发的。

是否有人知道可能导致此行为的原因或遇到类似问题?

祝你好运, 斯特芬

[编辑] 实际上,我忘记添加screenshot:)

2 个答案:

答案 0 :(得分:0)

试试这个

override func tableView(tableView: UITableView, commitEditingStyle editingStyle:
UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
    if editingStyle == .Delete {
        // Delete the row from the data source
        self.tableView.reloadData()
    }
}

答案 1 :(得分:0)

在研究了@maddy提到的更多方向之后,我发现了这个问题。

由于我想添加/删除列表中的最后一行以“正常”模式输入新数据,但不是“编辑”模式,我将覆盖 func setEditing 并调用< em> tableView.reloadData()那里。

override func setEditing(editing: Bool, animated: Bool) {
    super.setEditing(editing, animated: animated)
    tableView.reloadData() // Recall numberOfRowsInSection to show/hide the "new cell"
}

所以我现在必须找出,如何手动触发行号的计算,就是这样。

相关问题