Search code examples
iosswiftuitableviewsegue

I amt trying to dismiss my tableViewController in override func tableView(...didSelectRowAt...), but nothing happens


I want to return to my previous viewController, so I used the dismiss method, but when I select a cell nothing happens. This is the code that I have right now.

override func tableView(_ tableView: UITableView, didSelectRowAtindexPath: IndexPath) {


            delegate?.dataReceived(data: universityArray[indexPath.row].name)
            dismiss(animated: true, completion: nil)

    }

Solution

  • Form the top of my head, i can see two potential problems here

    1. The tableView delegate is not set
    tableView.delegate = self
    
    1. The viewController was not presented rather pushed, of that is the case try popViewController instead of dismiss
    self.navigationController?.popViewController(animated: true)
    

    Hope the problem was one of the above.