简体   繁体   English

UITableViewCell滑动不显示删除按钮

[英]UITableViewCell swipe does not show the delete button

I'm currently working on a UITableViewController demo which works just the way I wanted it to work. 我目前正在开发一个UITableViewController演示,它的工作方式与我希望的一样。

The only thing I don't get is the missing delete button, when swiping to the left on a row. 我唯一不知道的是在向左滑动时,缺少的删除按钮。

The "space" of the button and also the delete functionality are there, but neither the red rectangle button nor the text "delete" shows up. 按钮的“空格”以及删除功能都在那里,但是红色矩形按钮和文本“删除”均未显示。

This happens in the simulator and also on the device. 这会在模拟器中以及设备上发生。

Of course, I have implemented "edititingStyleForRowAtIndexPath' 当然,我已经实现了“ 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
    }
}

and 'commitEditingStyle' which is irrelevant for this, as it is triggered after the delete button has been touched. 和'commitEditingStyle'与此无关,因为它是在触摸删除按钮后触发的。

Does anyone have any idea what could cause this behavior or faced a similar issue? 有谁知道什么可能导致这种行为或面临类似的问题?

Best regards, Steffen 最好的问候,斯特芬

[Edit] Actually, I forgot to add a screenshot :) [编辑]实际上,我忘记添加屏幕截图了 :)

Try this 尝试这个

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

After researching more in that direction @maddy mentioned, I found the issue. 在提到这个方向进行了更多研究后,我发现了问题。

Since I want to add/remove one last row in the list to enter new data in "normal" mode, but not in "edit" mode, I'm overriding func setEditing and calling tableView.reloadData() there. 由于我想添加/删除列表中的最后一行以“常规”模式而不是“编辑”模式输入新数据,因此我覆盖了func setEditing并在那里调用tableView.reloadData()

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

So I now have to find out, how to manually trigger the calculation of row numbers and that's it. 因此,我现在必须找出如何手动触发行号的计算,仅此而已。

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

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