Reputation: 2942
I am following Apple documentation (page link) to add a tableview in empty ViewController.swift file. While adding protocols as shown below:
Class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// define the class
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 10
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "MyTestCell")
cell.text = "Row #\(indexPath.row)"
cell.detailTextLabel.text = "Subtitle #\(indexPath.row)"
return cell
}
I am getting error: “Type ViewController Does not confirm to protocol UITableViewDataSource. There's nothing much to do here. Could this be a bug?
Upvotes: 1
Views: 1485
Reputation: 35394
The 2 required functions are not within the class definition. Just move the closing bracket of the class to the end of the file.
Upvotes: 5