Hightower98 Hightower98 - 1 year ago 275
Swift Question

UITableView unrecognized selector sent to instance

I'm confused on what is going on I'm doing a tutorial on collection views as I'm fairly new to programming, and I believe I'm doing everything right but I get hit

-[UIView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance

Here is the tutorial:

import UIKit

class ViewController: UIViewController, UITableViewDataSource {

var categories = ["Action", "Drama", "Science Fiction", "Kids", "Horror"]

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return categories[section]

func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return categories.count

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! CategoryRow
return cell

Answer Source

Have you set Tableview delegate to UITableViewDataSource using storyboard or programmtically.?

set Tableview delegate to UITableViewDataSource programmtically.



using storyboard set Tableview delegate to UITableViewDataSource show below image.

enter image description here


check if you set UITableViewDataSource wrong to any other view.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download