Reputation: 1793
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;
}
}
Upvotes: 0
Views: 109
Reputation: 650
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.
Upvotes: 2
Reputation: 350
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.
Upvotes: 0
Reputation: 3777
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?
Upvotes: 0