0
votes

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

1
Hi @Ahsan can you verify that the type of the view controller in the xib matches the one in the code? you can see it when you open the xib, go to "file Owner" and tap on the "attributes inspector" can you verify that this is an exact match for your class name? - Sniro
@Ahsan please search for the string "searchResultTableView1" in your project. You might have an IBOulet that might have been changed or modified. Also, did you notice the "1" at the end of the string "searchResultTableView1". I hope that is intentional. - TheAppMentor
@TheAppMentor bro issue was that I was instantiating view controller with the UIViewController(nibname) method. I instantiated it with the class Constructor method and it is working perfectly fine now. - Ahsan

1 Answers

1
votes

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)