1

I don't quite understand this error or why I am receiving it. I have had a look at a couple other SO questions on this and have tinkered with my storyboard in attempt to fix the issue, but have had no success. Here is my code:

class Home: UIViewController, UITableViewDataSource, UITableViewDelegate {


    var images = [String]()
    var names = [String]()

    func getNames(array: inout Array<String>){
        for dict in State.event {
            array.append(dict["name"] as! String)
        }
    }

    func getImages(array: inout Array<String>){
        for dict in State.event {
            let cover = dict["cover"] as! NSDictionary
            let pictureURL = cover["source"] as! String

            array.append(pictureURL)
        }
    }

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

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        getNames(array: &names)
        getImages(array: &images)
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell

        let url = URL(string: images[indexPath.row])
        let imageData = try? Data(contentsOf: url!)
        cell.eventImage.image = UIImage(data: imageData!)
        cell.eventName.text = names[indexPath.row]

        return cell
    }    

}

error: -[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7ff437517770

  • If you are using storyboards, check out your outlets. Take a look at this question: https://stackoverflow.com/questions/2455161/unrecognized-selector-sent-to-instance – Tamás Sengel Dec 05 '17 at 13:10

1 Answers1

4

This is happened because you have set DataSource from Storyboard. but I think you have forgot to set Home as Class in Storyboard

enter image description here

Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98