20

I am trying to use UINavigationController. I have two views which are being created programmatically. When a UIButton is pressed on the first view, the second view should come to foreground.

But here application crash with exception:

loaded nib but the view outlet was not set

What can be cause of this and how to resolve it.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
erdemgc
  • 1,701
  • 3
  • 23
  • 43

6 Answers6

33

follo following steps

1) open your xib file then right click on files owner and drag to your first view

enter image description here

2) then bind that view with outlet of "view"

enter image description here

hope you will get it...

Nirav Gadhiya
  • 6,342
  • 2
  • 37
  • 76
17

Do This(You have no view in xib so add one and then do this):

enter image description here

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
6
  • Open the XIB file causing problems
    • Click on file's owner icon on the left bar (top one, looks like a yellow outlined box)
    • If you don't see the right-hand sidebar, click on the third icon above "view" in your toolbar. This will show the right-hand sidebar
    • In the right-hand sidebar, click on the third tab--the one that looks a bit like a newspaper
    • Under "Custom Class" at the top, make sure Class is the name of the ViewController that should correspond to this view. If not, enter it
    • In the right-hand sidebar, click on the last tab--the one that looks like a circle with an arrow in it
    • You should see "outlets" with "view" under it. Drag the circle next to it over to the "view" icon on the left bar (bottom one, looks like a white square with a thick gray outline
    • Save the xib and re-run

Thanks,

sagarcool89
  • 1,366
  • 8
  • 16
6

If you are not seeing the "view" outlet to select from on the "Connections inspector" (rightmost) tab, I found that I had to go back to a generic view controller (e.g., UICollectionViewController) for the File's Owner Custom Class instead of my subclass that I had entered previously. After closing and reopening Xcode, the view outlet appeared again so I connected it as described in sagarcool89's answer. I then set my File's Owner Custom Class back to my subclass and have finally moved past this error.

Gary Z
  • 155
  • 2
  • 6
  • This worked for me! Didn't have to close Xcode at all, just changed the class to UIViewController, linked the view, and then changed it back to my subclass. – Jonathan Cabrera Jan 08 '18 at 21:06
  • Xcode has been updated many times since June 2014 so a change in behavior is not surprising. I fought this bug for days so once I had it working, I wasn't about to break it again to test if exiting Xcode was necessary. – Gary Z Jan 11 '18 at 01:06
3

Select File's owner of your .xib, open the Identity Inspector, make sure Custom Class is set to the same name as your controller's class name. If you create IB file and Controller separately(in separate steps), you might forget to check this.

Thomas E
  • 3,808
  • 2
  • 20
  • 13
3

If you have tried everything and you still get this error, try re-creating the class file from scratch but remember to select the "Also create XIB file" check box. This will auto link up a few items that are not linked when creating these files separately. After this is created, you can likely cut and paste everything onto the new XIB and it should work fine.

Travis M.
  • 10,930
  • 1
  • 56
  • 72
  • 1
    I ran into the same issue. Everything appeared to be correct in the previous files, with this solution I got it working. Attempted a side-by-side comparison after the fact to see if it was something I missed but couldn't see anything. My ownership and view outlet were set correctly. – mriddle89 Aug 18 '16 at 04:30