I have being doing the exercises, and did the worksheet (module3 lesson 5) on Protocols & Delegates, but I got stuck!!! Please help. Xcode tells me that ViewController is not conforming to the protocol.
(I thought I did…)
Here is what my worksheet looks like… What am I missing / doing wrong? HELP PLEASE
import UIKit
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var myTableView: UITableView!
let dataArray = ["bird","dog","cat","turtle","bear"]
override func viewDidLoad() {
super.viewDidLoad()
myTableView.delegate = self
myTableView.dataSource = self
// MARK: UITableView Protocol Method IMPLEMENTATION
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
//Get the data for this row
let rowData = dataArray[indexPath.row]
//Get a cell to display
let cell = tableView.dequeueReusableCell(withIdentifier: "BasicCell", for: indexPath)
cell.textLabel?.text = rowData
//Return the cell
return cell
}
}
}