Reputation: 5340
Using Xcode 8.2
and Swift 2.3
I have a view controller files namVcc.swift and namVccUI.xib
I am trying to initialize the view controller from xib file but getting error
|*| Try 1 :
let namVccVar = UINib(nibName: "namVccUI", bundle:
nil).instantiateWithOwner(nil, options: nil)[0] as! namVcc
navigationController?.pushViewController(namVccVar, animated: true)
|*| Try 2 :
let namVccVar = namVcc(nibName: "namVccUI", bundle: nil)
navigationController?.pushViewController(namVccVar, animated: true)
Error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'namVccUI'
I also checked the properties of xib file > Target Membership and it's checked.
What else could be the problem?
Upvotes: 0
Views: 1187
Reputation: 5887
I am getting a similar but slightly differently worded error when I try to set this up. I get
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "namVccUI" nib but the view outlet was not set.'
when I just create an empty project with your code in Try 2
and a new, clean .xib file. I had to explicitly set the Referencing Outlet of the UIView in the .xib file to the File's Owner and I had to ensure that the Custom Class of the File's Owner in the .xib was set to namVcc. I never could get Try 1
to work.
Upvotes: 1