繁体   English   中英

SwipeCellKit操作将不会执行segue

[英]SwipeCellKit action won't perform segue

我将SwipeCellKit用于我的“待办事项列表”应用程序。 当用户向左滑动时,它会删除该项目,但是当用户向右滑动时,我希望他能够在此项目上设置提醒,因此我创建了一个设置提醒的操作

此操作应执行segue,将用户带到其中带有日期选择器的自定义弹出窗口。 问题是,当我单击按钮来设置提醒时,模拟器会退出,并出现未捕获的异常。 我已经尝试过从此按钮执行删除操作,而该按钮可以正常工作,我还尝试过从模拟器退出的此按钮对另一个视图控制器执行另一次搜索。 有人可以告诉我我在做什么错吗? 这是我的代码:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {        if orientation == .left {
        guard isSwipeRightEnabled else { return nil }
        let setReminder = SwipeAction(style: .default, title: "Set a reminder") { action, indexPath in

           self.updateModelByAddingAReminder(at: indexPath)

        }
        setReminder.image = UIImage(named: "reminder-icon")
        return[setReminder]
    }else{

        let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in

           self.updateModel(at: indexPath)

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


       // return [setReminder, deleteAction]
        return [deleteAction]
    }

好的,我在您选择的单元格中发现了问题。 From doc内置的.destructive和.destructiveAfterFill扩展样式被配置为在调用操作处理程序时自动执行行删除(自动实现)。 您需要在editActionsForRowAt中为单元格使用破坏性样式。 或使用其他选项,例如

func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> SwipeTableOptions {
    var options = SwipeTableOptions()
    options.transitionStyle = .border

    if orientation == .left{
        //or none
        options.expansionStyle = .selection
    }else{
        options.expansionStyle = .destructive
    }

    return options
}

希望对您有所帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM