Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reasons for an IBOutlet to be nil

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

I have one in may application which is always nil, even if I recreate everything from scratch (declaration and control).

like image 733
AP. Avatar asked Jun 03 '11 05:06

AP.


3 Answers

It could be that your nib is messed up, but I find a common reason is having two instances where you think you only have one, and the one you're using in your code is not the one you connected.

like image 121
Chuck Avatar answered Sep 23 '22 08:09

Chuck


If you've also defined a loadView method that creates the view, it is possible based on how you initialize it. If you initialize it using alloc-init and the nib name is not the same as class name, then you can have a case where the outlet is nil. But Chuck's answer seems more reasonable to assume.

like image 35
Deepak Danduprolu Avatar answered Sep 25 '22 08:09

Deepak Danduprolu


One reason I just got stung by: If the nib file is not included in the target resource files for some reason (like you had the targets unchecked when you added it to the project), Xcode doesn't throw an error but all the outlets from that nib are going to be null...

like image 36
shipmaster Avatar answered Sep 23 '22 08:09

shipmaster