Use of unresolved identifier 'performSegue' in Tableviewcell

Hi everyone,

I have table view in main table view. i want go details view when click sub tableview's cell and put didSelectRowAt function and i prepare "goDetail segue". However when i wrote that codes;

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        _selectedVideo = self._videos[indexPath.row].id
        performSegue(withIdentifier: "goVideoDetails", sender: nil)
    }
    func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        
        if segue.identifier == "goVideoDetails" {
            let destinationVC = segue.destination as! SpeechDetails
            destinationVC._chosenVideo = _selectedVideo
        }
    }

performSegue(withIdentifier: "goVideoDetails", sender: nil) // Use of unresolved identifier 'performSegue'

I knew reason because perform segue can't use in table view cell but i dont have any option. i should use that table in main table. Have i got any option for go detail page? I need helps or hits.

Am I correct in assuming you have placed a UITableView in a UITableViewCell?

If so, and you are trying to write the above code in a UITableViewCell subclass, the problem will be that that class doesn't possess a performSegue method; that only exists in the UIViewController class.

Normally, when placing something complex like a UITableView in a cell, you should first add a Container view and place a UITableViewController inside that; that way, the correct hierarchy of view controllers can be maintained.

You are not really giving us much information about the structure of what you are attempting to do.

This would commonly be handled with a delegate protocol (or more than one). The UITableViewDelegate object will have a delegate that is a view controller (or another object that knows the view controller). So didSelectRowAt indexPath will call its delegate and the event will be passed up the chain to the view controller.

Terms of Service

Privacy Policy

Cookie Policy