2

I have a nib ViewController that I'm loading into a scroll view container using this code:

let friendsFeedVC = UIViewController(nibName: "FriendsFeedViewController", bundle: nil)

In my storyboard for the FriendsFeedViewController.xib file, I added a navigation bar and dragged an IBOutlet into the FriendsFeedViewController.swift file to hook up the outlet like I normally do.

When I run the app and the Nib is loaded in the scroll view, it causes a crash saying:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key navBar.' *** First throw call stack: (0x1847b5900 0x183e23f80 0x1847b55c0 0x1850aff74 0x189817f1c 0x189972cb8 0x1846df3ac 0x1899716a0 0x18981b33c 0x1895e4250 0x1894a7d6c 0x1894a7cc4 0x100096b4c 0x100097a40 0x1894a80c0 0x1894a7cc4 0x1894aeab4 0x1894abfa0 0x189521cd0 0x1000fb904 0x1000fbae8 0x18951d704 0x18974c130 0x1897504b8 0x18974d5c0 0x185d6b790 0x185d6bb10 0x18476cefc 0x18476c990 0x18476a690 0x184699680 0x189516580 0x189510d90 0x1000fbfec 0x18423a8b8) libc++abi.dylib: terminating with uncaught exception of type NSException

Here are screenshots showing that the IBOutlet is set up. Is it not being instantiated? What's the solution? I have cleaned the project and I don't have any random outlets floating around from previous use. Also, the Nib loads fine if I remove the IBOutlet, so the problem only comes once I hook it up I guess.

enter image description here

enter image description here

cb428
  • 485
  • 1
  • 6
  • 19
  • http://stackoverflow.com/a/8087739/2206489 – Keshav Dec 26 '15 at 20:41
  • I don't have any previous outlets left over though. Did you see my screenshot? – cb428 Dec 26 '15 at 20:44
  • even I have faced the same issue. but every time the error was the IBOutlet connection only. – Keshav Dec 26 '15 at 20:50
  • that's so weird, because I really can't find any issues with the connection and if I remove the one I currently have the app launches fine. Then once I add a new connection or even delete the navigation bar and re-add, it breaks. – cb428 Dec 26 '15 at 20:51
  • you are connecting navBar to UINavigationBar. All you need is to connect the title in the navigation bar to IBOutlet – Keshav Dec 26 '15 at 20:54
  • Ok I dragged the title into the .swift file as `@IBOutlet weak var navTitle: UINavigationItem!` but it caused the same error. Is that what you meant? Sorry for all the questions I'm new – cb428 Dec 26 '15 at 20:57
  • can you delete the navBar IBoutlet connection and check whether it works? – Keshav Dec 26 '15 at 21:02
  • I deleted it yeah, also just to try I removed the nav bar object and put in a UIButton just to see if it was the Nav Bar that was the issue, but even connecting the UIButton was causing a crash. I was thinking they weren't being instantiated but idk. – cb428 Dec 26 '15 at 21:04
  • try to hover on the referenced Outlets. Does anything gets highlighted in storyboard? – Keshav Dec 26 '15 at 21:08
  • no nothing highlights – cb428 Dec 26 '15 at 21:10
  • that means what ever outlet which has been created, is not correct. – Keshav Dec 26 '15 at 21:14
  • actually it is highlighting i was hovering in the wrong spot. – cb428 Dec 26 '15 at 21:20
  • Did you set the file's owner to be _FriendsFeedViewController_? – Leonardo Wistuba de França Dec 26 '15 at 21:20
  • Yes. And I had to correct myself before, I was checking the highlight in the referencing outlets for the object instead of File's Owner. It is being set up properly but still crashes. – cb428 Dec 26 '15 at 21:21
  • Thanks for everyone's help. I found the issue. let friendsFeedVC = UIViewController(nibName: "FriendsFeedViewController", bundle: nil) should be let friendsFeedVC = FriendsFeedViewController(nibName: "FriendsFeedViewController", bundle: nil) – cb428 Dec 26 '15 at 21:29

1 Answers1

2

Found the issue:

let friendsFeedVC = UIViewController(nibName: "FriendsFeedViewController", bundle: nil)

should be

let friendsFeedVC = FriendsFeedViewController(nibName: "FriendsFeedViewController", bundle: nil)
cb428
  • 485
  • 1
  • 6
  • 19