0

I have a storyboard set up with a View controller . the view controller is divided into two halves , one half is a UI date picker and the other is a table view . When I set the view controller as the delegate and datasource , I get the following error

reason: '-[UIViewController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7fdb29b4d9e0'

My View controller is defined in the following way

import Foundation
import UIKit

class CustomViewController:  UIViewController , UITableViewDelegate , UITableViewDataSource{

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


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

        return 3;
    }


    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

        var sampleCell = tableView.dequeueReusableCellWithIdentifier("cell") as! UITableViewCell

        return sampleCell;

    }



}

3 Answers 3

2

Are you sure if your view's class is your table's class? I got the same error when I forgot to set my view's class.

Sign up to request clarification or add additional context in comments.

1 Comment

Glad I helped :) And thanks now I can comment everywhere haha :)
0

Do you have an IBOutlet property that is connected to the UITableView in the storyboard/nib? Is the view controller set as the delegate and dataSource for the table view?

1 Comment

no IBOutlets defined in the storyboard . the view controller is set as the datasource and delegate , when I use the whole view controller as a storyboard it works fine, it fails when I divide the view controller like I mentioned above
0

You need to set an outlet for the UITableView and set the delegates:

Then in viewDidLoad set the tableView's datasource and delegate to self since the ViewController implements the protocol.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.