【问题标题】:editActionsForRowAtIndexPath was called but no action button is shown when the UITableViewCell is slidededitActionsForRowAt IndexPath 被调用,但 UITableViewCell 滑动时没有显示操作按钮
【发布时间】:2015-06-24 11:02:16
【问题描述】:

我实现了 editActionsForRowAtIndexPath 和 commitEditingStyle,滑动工作正常,但 UITableViewCell 上没有显示任何操作按钮

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {  

    let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Delete" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in  
          // I did some work here  
    })  

    return [deleteAction]  
}  

有人知道如何在滑动时显示操作按钮吗? (目前,单元格滑动,但其后面是白色背景,没有操作按钮。单击此白色背景也不会引起任何类型的响应)

注意:我在另一个 ViewController 中实现了 editActionsForRowAtIndexPath 并且它可以工作。 (动作按钮既出现又响应点击事件)

【问题讨论】:

  • 你实现canEditRowAtIndexPath了吗?
  • 是的,我做了,但还是不行
  • 请发布您的commitEditingStyle 代码

标签: ios swift uitableview tableviewcell uitableviewrowaction


【解决方案1】:

我遇到了同样的问题,就我而言,我意识到我的自定义单元格对于表格视图来说太宽了。我注意到了这一点,因为没有显示配件。在 iPad 模拟器上运行它后,我看到了按钮。

【讨论】:

    【解决方案2】:

    这里的事件应该是commitEditingStyle才能使用滑动按钮操作

    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
            if (editingStyle == UITableViewCellEditingStyle.Delete) {
                // handle delete (by removing the data from your array and updating the tableview)
            }
    }
    

    【讨论】:

      【解决方案3】:

      commitEditingStyle 为空,因为它是滑动所必需的。 editActionsForRowAtIndexPath 已实现,这在一个 viewController 中有效,但在另一个 viewController 中无效

      代码如下

       func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
      
          }
      
      
      func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {
      
          let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Delete" , handler: { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in
              //some code here
          })
      
      
          return [deleteAction]
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-03-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-31
        • 1970-01-01
        • 2016-08-01
        相关资源
        最近更新 更多