Search code examples
iosswifttableviewxib

loading ViewController(containing xib) using xib


I am trying to create Viewcontroller with xib. Here this viewcontroller contains a tableview. If I load viewController with connecting tableview with @IBOlet reference then view controller works fine. But when I connect tableview reference with my xib viewcontroller then at runtime, I get this error.

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fc02602d8e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key searchResultTableView1.'

I am completely sure that my tableview is connected with the right reference. I don't know which step, I am missing

here are pictures of how I am loading viewcontroller from xib

searchViewController.xib searchViewController.xib pic here

searchViewController.swift searchViewController pic here

loading from the main view controller loading from main view controller picture here


Solution

  • after 4 to 5 hours now I got to the point that I was instantiating xib viewcontroller using

    let vc1 = UIViewController(nibName: "SearchViewController", bundle: nil)

    so now I tried to instantiate a view controller with viewcontroller constructor

    let vc1 = SearchViewController(nibName: "SearchViewController", bundle: nil)