我正在按照教程创建一个简单的待办事项应用程序,我希望用户能够使用SwipeCellKit向左滑动编辑单元格,向右滑动删除单元格。我已经创建了一个swipetableviewcontroller来运行代码,这样我就可以在其他视图控制器中调用它,并使用了github repo SwipeCellKit上的代码文档。这是我添加的代码:
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]
}我在哪里实现向左的方向?(请善待我,我只是个新手,如果这是一个愚蠢的问题,我很抱歉)
发布于 2018-11-09 20:49:37
这一行阻止您实现向左方向,因为guard语句只检查向右方向。
guard orientation == .right else { return nil }如果您想同时处理这两种情况,则应该将guard语句更改为If语句,如下所示:
if orientation == .right{
//Do Something with right swipe
}
else{
//Do Something with left swipe
}https://stackoverflow.com/questions/53222123
复制相似问题