0
votes

Have some question that I can't figure out. I have single static cell in xib file and I want to make segue from detail disclosure accessory of that cell to other view controller.

Guess that I have to use this method:

func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    self.performSegue(withIdentifier: "SegueID", sender: self) // #ERROR
}

But I have an error:

Could not cast value of type 'Lists.ListViewController' (0x104c0e7b8) to 'UITableViewCell' (0x106875bf8).

How can I create this segue correctly?

1
Why you want sender as disclosure button class? - Nirav D
@NiravD that was just example. I've just edited question. - wm.p1us
Where you are getting these error? - Nirav D
@NiravD in the line self.performSegue.. - wm.p1us

1 Answers

5
votes

If you want to access the cell in prepareForSegue you can try like this way.

func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
    //Pass the indexPath as sender
    self.performSegue(withIdentifier: "SegueID", sender: indexPath)
}

Now access that indexPath in prepareForSegue.

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "SegueID" {
        let nextVC =  segue.destination as! DestinationVC
        if let indexPath = sender as? IndexPath,
           let cell = self.tableView.cellForRow(at:indexPath) as? CustomCell {
              //access your cell here
        } 
    }
}