Reasons for IBOutlet to be Null

What are the reasons why an IBOutlet (connected) might be nil ?

I have one can application that is always nil , even if I recreate everything from scratch (declaration and management).

+7
source share
6 answers

Maybe your nib is messed up, but I find that the common reason is that you have two instances in which you think you only have one, and the one you use in your code is not the one you connected.

+4
source

If you also define the loadView method that creates the view, this is possible based on how you initialize it. If you initialize it using alloc-init , and the nib name does not match the class name, then you may have a case where the output is zero. But Chuck's answer seems more reasonable to suppose.

+2
source

One of the reasons why I just stung: If for some reason the nib file is not included in the target resource files (for example, if you did not specify the goals when you added them to the project), Xcode does not throw an error, but all exits this nib will be null ...

+1
source

One possibility: Suppose an IBOutlet container is a singleton object with a function such as:

 + (singletonObject*) sharedInstance { if(!gGlobalSingletonPointer) { gGlobalSingletonPointer = [[singletonObject alloc] init]; } return gGlobalSingletonPointer; } 

You create a single object "on demand" if it does not already exist. You store a global pointer to it, as you create it, in this function.

If you also create such an object in InterfaceBuilder and connect its outputs, this object will be created without calling sharedInstance. If you subsequently call sharedInstance, a new object is created (without IBOutlet connections).

The solution is to update the global pointer in the singletonObject init or awakeFromNib function.

0
source

Are you using a UINavigationController?
If so, open your MainWindow.xib in IB and verify that the name of the root controller is set correctly in the Attributes Inspector.

Why won't it be installed correctly? One reason is that the β€œrename” refactoring does not update this, and then the insides will not find a nip with which you can connect your user interface. Or you renamed the thread yourself and did not update this field.

0
source

Are you doing something unusual with File Owner? If you are not in one of the situations when the downloaded file is downloaded automatically (the main file is loaded by the application or nib loaded by the view controller, document, or window controller), then you must download the program code .

0
source

All Articles