Zak Freeman
Zak Freeman

Reputation: 33

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

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

Upvotes: 1

Views: 1330

Answers (1)

Prashant Tukadiya
Prashant Tukadiya

Reputation: 16446

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

Upvotes: 4

Related Questions