I am fairly new to iOS and I am trying to make a table view controller. When coding, I get the error message in my title. It is obvious that I am doing something wrong. Can someone please explain to me what I am doing wrong. I will leave my code below.
Please note that I am not using a storyboard.
class settingsViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let elements = ["horse", "cat", "dog", "potato","horse", "cat", "dog", "potato","horse", "cat", "dog", "potato"]
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
// Error is on the following line
tableView.delegate = self
tableView.dataSource = self
super.viewDidLoad()
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return elements.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "customCell") as! CustomTableViewCell
cell.cellView.layer.cornerRadius = cell.cellView.frame.height / 2
cell.animalLbl.text = elements[indexPath.row]
cell.animalImage.image = UIImage(named: elements[indexPath.row])
cell.animalImage.layer.cornerRadius = cell.animalImage.frame.height / 2
return cell
}
}