Search code examples
swiftsegueuitableviewrowaction

Segue from row action?


I have row actions and want the user to be able to click them, then be segued to the new VC along with the info for the object in the cell indexpath. This is my current code:

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
    let update = UITableViewRowAction(style: .normal, title: "Update") { (action, indexPath) in
        let cell = tableView.cellForRow(at: indexPath)
        self.performSegue(withIdentifier: "XXXXXX", sender: cell)
    }
    update.backgroundColor = UIColor.blue
    return [update]
}

My idea was that i can set cell as the indexpath the row action is on and then segue to the VC I want.

Issue is, obviously you cant draw a segue in IB from a row action, so how am i supposed to create this? I know i could make it so the user can select the cell row to be segued but i want it specifically on the row action not on the cell itself.

I appreciate any help with how this is achieved!

edit: to suggest how this Q is different from the proposed, Im not able to create the segue in storyboard for a row action to be able to reference it


Solution

  • Resolved, As commented you can create the segue in the IB at a VC level rather than on row actions specifically, then assign that segues id to the row actions using performSegue(withIdentifier:sender:) as proposed in my question.