2

Are you required to create a default implementation for optional functions if you are going to provide an implementation in subclass?

Or am I doing it wrong? Or Xcode 10.2 is to blame?

Scenario A:

  • Xcode 10.1 : viewForHeader is called

  • Xcode 10.2 : viewForHeader is never called (when running Release config), so no header is presented on screen. Did a breakpoint, print to console. So pretty confident it never got called.

class SomeVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
    @IBOutlet weak var tableView: UITableView!

    var tableViewModel: TableViewModel!

    override func viewDidLoad(){
        super.viewDidLoad()

        tableView.dataSource = self
        tableView.delegate = self

        tableView.rowHeight = UITableView.automaticDimension
        tableView.sectionHeaderHeight = UITableView.automaticDimension
        tableView.sectionFooterHeight = UITableView.automaticDimension

    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tableViewModel.numberOfRows(in: section)
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return tableViewModel.numberOfSections
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: tableViewModel.cellReuseIdentifier(for: indexPath))!

        return cell
    }
}

class SomeSubclass: SomeVC{
   func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
     //some implementation not called on xcode 10.2 on Release config.
     return UILabel() //simplicity sake
  }

}

Scenario B: Works on both Xcode 10.1 and 10.2

class SomeVC: UIViewController, UITableViewDelegate, UITableViewDataSource{
 @IBOutlet weak var tableView: UITableView!

    var tableViewModel: TableViewModel!

    override func viewDidLoad(){
        super.viewDidLoad()

        tableView.dataSource = self
        tableView.delegate = self

        tableView.rowHeight = UITableView.automaticDimension
        tableView.sectionHeaderHeight = UITableView.automaticDimension
        tableView.sectionFooterHeight = UITableView.automaticDimension

    }

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tableViewModel.numberOfRows(in: section)
    }

    func numberOfSections(in tableView: UITableView) -> Int {
        return tableViewModel.numberOfSections
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: tableViewModel.cellReuseIdentifier(for: indexPath))!

        return cell
    }
     func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
      return nil
  }
}

class SomeSubclass: SomeVC{
   override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?{
     //some implementation
  }
}

If someone can show a changelog on Xcode 10.2 that details this change OR a radar to Xcode 10.2 bug would be helpful

EDITED: Created a new project and can't seem to replicate it. I'll dismiss as build issue

Cœur
  • 37,241
  • 25
  • 195
  • 267

0 Answers0