我正在按照一个教程创建一个简单的待办事项应用程序,我希望用户能够使用swippecellkit向左滑动编辑单元格,向右滑动删除单元格。我创建了一个swipableviewcontroller来运行代码,以便在其他viewcontroller中调用它,并使用了github repoSwipeCellKit上的代码文档。这是我添加的代码:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
guard orientation == .right else { return nil }

let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
    // handle action by updating model with deletion
}

// customize the action appearance
deleteAction.image = UIImage(named: "delete")

return [deleteAction]
}

我在哪里执行左方向?
(请客气,我只是个新手,如果这是个愚蠢的问题,我会道歉)

最佳答案

这一行阻止您实现左方向,因为guard语句只检查右方向。

guard orientation == .right else { return nil }

如果要处理这两种情况,则应将guard语句更改为如下所示的If语句:
if orientation == .right{
   //Do Something with right swipe
}
else{
  //Do Something with left swipe
}

关于swift - 如何在SwipeCellKit中实现左右滑动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53222123/

10-10 20:39