“loaded nib but the view outlet was not set” excep

2019-01-14 21:50发布

问题:

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.

回答1:

follo following steps

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

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

hope you will get it...



回答2:

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



回答3:

  • 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,



回答4:

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.



回答5:

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.



回答6:

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.