如何实现右滑完成(Todo List)

How to achieve swipe right to complete (Todo List)

我正在做一个todo list应用,现在我可以用这些代码实现左滑删除

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    let delete = UITableViewRowAction(style: .Normal, title: "Delete") { action, index in
        print("Delete button tapped")
    }
    delete.backgroundColor = UIColor.redColor()
    return [delete]
}

而且我想我搜索了整个互联网,但 none 这些解决方案可以完成向右滑动的工作,同时对我也很好用。我正在使用 swift 2.0,Xcode 7 beta 5。

以前有人做过吗?

它认为这个项目可以帮助你进一步...

SBGestureTableView: Swift UITableView subclass 支持在邮箱中滑动行并长按移动行。

如果你不想使用这个class。你可以看到那里的源代码,你首先需要弄清楚用户是从左向右滑动还是从右向左滑动。然后从那里开始。

使用提交编辑风格

 func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {

    let thisTask = fetchedResultsController.objectAtIndexPath(indexPath) as! TaskModel

    if thisTask.completed ==  true {thisTask.completed = false}
    else {thisTask.completed = true}
    (UIApplication.sharedApplication().delegate as! AppDelegate).saveContext()
}

我正在使用 CoreData 来存储我的信息,我存储的其中一件事是它是否完成,当用户在 tableview 上向右滑动时,它会将完成的更改为 true,我有两个部分,一个用于未完成的任务,一个用于完成

我终于成功地将 SBGestureTableView 转换为 swift 2.0 语法并在 github.com/theniceboy/SBGestureTableView/tree/swift-2.0 上发布了它。不过还是要谢谢大家!