Search code examples
iosswiftsegueswipe

SwipeCellKit action won't perform segue


I'm using SwipeCellKit for my TO DO List app. When the user swipes left it deletes the item, but when the user swipes right I want him to be able to set a reminder on this item, so I've created an actionset a reminder

this action should perform a segue which brings the user to a custom popup with a date picker in it. The problem is that when I click on the button to set a reminder the simulator quits with an uncaught exception. I've already tried to perform deletion from this button it works perfectly, I've also tried to perform another segue to another view controller from this button the simulator quits. Could someone tell me what I'm doing wrong here? Here's my code:

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]
    }

Solution

  • Ok, I found problem in your options for cell. From doc The built-in .destructive, and .destructiveAfterFill expansion styles are configured to automatically perform row deletion when the action handler is invoked (automatic fulfillment). And you need use destructive style for cell in editActionsForRowAt. Or use another options, for example

    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
    }
    

    Hope it's help.