0

I am getting exceptions on trying to dequeue reusable cells. It works fine when I set the initial scene arrow to points to the scene with the list view, but when I try to load the scene at runtime I get the exception

'unable to dequeue a cell with identifier SessionListTableViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

The exception happens here on the call to tableView.dequeueReusableCell

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    guard let cell = tableView.dequeueReusableCell(withIdentifier: "SessionListTableViewCell", for: indexPath) as? SessionListTableViewCell else {
        fatalError("The dequed cell is not an instance of SessionListTableViewCell")
    }

I am pretty sure that I have registered the cell type properly in IB. The correct cell type appears in IB as a child of the ListViewTableController and Content is set to Dynamic Prototypes.

It works if I set the initial scene arrow to point to the scene. It doesn’t work if I try to load the same scene at runtime. My Table View Cell Identifier seems to be properly configured in IB.

I was not able to register the cell type in code as I get getting a compile error here: tableView.register(SessionListTableViewCell.self, forCellWithReuseIdentifier: "SessionListTableViewCell") “Cannot invoke 'register' with an argument list of type '(SessionListTableViewCell.Type, forCellWithReuseIdentifier: String”

ohthepain
  • 2,004
  • 3
  • 19
  • 30

1 Answers1

0

I wasn't loading the ViewController from the storyboard correctly.

Here is the correct code in case anybody else runs into this issue:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let poseViewController : PoseViewController = storyboard.instantiateViewController(withIdentifier: "Pose Menu") as! PoseViewController
self.present(poseViewController, animated: true, completion: nil)

You first need to give your UIViewController a storyboard identifier, as shown in this post: How do I give an "identifier" to a view controller within my storyboard?

ohthepain
  • 2,004
  • 3
  • 19
  • 30