【问题标题】:editActionsForRowAtIndexPath call programmaticallyeditActionsForRowAt IndexPath 以编程方式调用
【发布时间】:2016-08-01 20:44:19
【问题描述】:

我在 UITableView 中有 UIButton 作为附件视图。我实现了委托方法“editActionsForRowAtIndexPath”。当我滑动一切都很好,但是当我按下附件按钮时我需要这种效果。

【问题讨论】:

  • 你能解释一下你在找什么吗?我不太明白你的问题。
  • @fbara 这个问题很清楚。问题是询问如何通过代码而不是用户滑动来显示单元格右侧的额外按钮。
  • @rmaddy 这个问题我不清楚,因此我提出了要求。随意回答问题,而不是就我清楚的和不明白的向我提供建议。或者,也许,下次只需评论“这就是 OP 所要求的......”,这将更具建设性。

标签: ios objective-c uitableview methods accessoryview


【解决方案1】:

您可以在cellForRowAtIndexPath 中添加自定义附件按钮。

let button = UIButton(frame: CGRectMake(0,0,20,20))
button.setImage(UIImage(named: "yourButtonImage"), forState: .Normal)
button.tag = indexPath.row
button.addTarget(self, action: "accessoryButtonFired:", forControlEvents: .TouchUpInside)
cell.accessoryView = button

现在在selector 方法中执行编辑操作

func accessoryButtonFired(sender: UIButton) {
    //to delete the row
    yourArray.removeAtIndex(sender.tag)
    self.tableView.deleteRowsAtIndexPaths([NSIndexPath(forRow: sender.tag, inSection: yourSection)], withRowAnimation: .Automatic)
}

【讨论】:

  • 问题不是问如何实现额外的按钮,而是问如何通过代码显示额外的按钮,而不是要求用户滑动单元格。
  • 编辑accessoryButton的答案
  • 虽然这显示了一种添加附件视图的方法,但 OP 不希望该按钮简单地删除该行。 OP 希望该按钮模拟向左滑动,这将显示单元格后面的额外操作按钮。
【解决方案2】:

我使用 GitHub 上的 MGSwipeTableCell 类解决了这个问题。这个对我有用。谢谢。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多