2
extension FormViewController : UITableViewDelegate {
    public func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath?
    public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
    public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat
    public func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
    public func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
    public func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
    public func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
}

extension FormViewController : UITableViewDataSource {
    public func numberOfSectionsInTableView(tableView: UITableView) -> Int
    public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?
    public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String?
}

class NotifiableFormViewController: FormViewController

Why can't I implement and override the DataSource and TableViewDelegate? Error:"Method does not override any of it's superclass method"

class FriendsTableViewController: NotifiableFormViewController{
    override func numberOfSections(in tableView: UITableView) -> Int {
        return 3
    }

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }

    override func tableView(tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath)

        cell.textLabel?.text = "Section \(indexPath.section) Row \(indexPath.row)"

        return cell
    }

    override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        return "Section \(section)"
    }
}
Gavin
  • 2,784
  • 6
  • 41
  • 78

3 Answers3

2

more simply, remove the word override because you're not overriding the method, you are implementing it

Russell
  • 5,436
  • 2
  • 19
  • 27
0

By definition, extensions can only add functionality to existing classes. It can not change, that includes overriding, the existing implementation.

halfer
  • 19,824
  • 17
  • 99
  • 186
Vandan Patel
  • 1,012
  • 1
  • 12
  • 23
0

UITableViewDataSource and UITableViewDelegateare just protocol If you want override it, you implement above functions in NotifiableFormViewController

then override in your FriendsTableViewController

but if not implement in your super class, then you can't override it (nothing override implemented delegate or datasource function)

Cruz
  • 2,602
  • 19
  • 29