editActionsForRowAtIndexPath为一节iOS Swift
正如你在图像中看到的,在这个tableView中有两个部分。 我可以知道如何pipe理在第一节中启用editActionsForRowAtIndexPath吗?
这是我的代码,使tableViewCell有一个行刷…
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { let complete = UITableViewRowAction(style: .Normal, title: "Complete") { action, index in print("more button tapped") } complete.backgroundColor = UIColor.greenColor() return [complete] }
您可以使用indexPath.section来决定您正在设置哪个部分,但是您应该使用tableView:canEditRowAtIndexPath:indexPath:
当您要启用编辑时告诉表视图。
Swift 2
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool{ return indexPath.section == 0 }
Swift 3
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return indexPath.section == 0 }