0

App keeps terminating/crashing due to tableView:numberOfRowsInSection unrecognized selector sent to instance when cell is clicked.

I've ensured that I have added the dataSource and delegate protocols to both my swift file and my TableView. I have also ensured that the swift file connected to the ViewController is the correct one. Whenever I select a cell in the TableView it crashes.

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return values.count
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)

        let mainData = values[indexPath.row] as? [String:Any]

        cell.textLabel?.text = mainData?["listName"] as? String

        return cell
    }

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        performSegue(withIdentifier: "selectList", sender: self)
    }
emavro
  • 1
  • The error shows `UIViewController`, nor your specific view controller class. – rmaddy May 03 '19 at 00:31
  • Thank you @rmaddy for your response. Should I be looking somewhere else in my program? – emavro May 03 '19 at 00:40
  • You didn't set the correct classname for your view controller in the storyboard. – rmaddy May 03 '19 at 00:41
  • I see, it was because then view that my segue takes me to did not have a swift file attached to it yet. You comment did point me in the right direction - I appreciate your help! – emavro May 03 '19 at 01:04

0 Answers0