Reputation: 147
I'm trying to convert my UITableViewController
to a UIViewController
with a UITableView
element. I changed the superclass to UIViewController
, added the UITableViewDelegate
, added a local UITableView
(which I linked to my table view in storyboard), and set tableView.delegate = self
. Now I'm trying to override the tableView()
methods so I can populate my cells. However, it's not letting me do this - "Method does not override any method from its superclass". Here's the relevant code:
class MenuViewController: UIViewController, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Click Item"
tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "menuItemCell")
tableView.delegate = self
}
Is there something I'm missing? I checked similar stackoverflow questions and this is what they said to do. I'm pretty new at all this so I could just be overlooking something.
Upvotes: 0
Views: 1979
Reputation: 4286
Since you are no longer writing a subclass of UITableViewController
you no longer override its delegate and datasource functions, but you are providing your own implementation to conform to those protocols. Swift strictly checks if the method you are declaring to override is in fact already implemented in the base class. This was true with the UITableViewController
, but it's no longer the case with UIViewController
.
In short: drop the override
keyword from the delegate and dataSource functions.
Upvotes: 4