Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does [[UIApplication sharedApplication] delegate]; return a nil object

Tags:

iphone

I have an iphone application with multiple views and related controllers and xib files. In the controller for the first view that is loaded I am trying to access the delegate for the application but the object that is returned is nil

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];

Any ideas why it would be nil?

like image 880
Liam Avatar asked Jun 16 '09 10:06

Liam


1 Answers

Because it is not (yet) set. The UIApplication delegate is usually instantiated and set from the MainWindow nib file. If you access it before the nib is loaded completely (e.g. an init method in a controller in the same nib), it is nil.

like image 106
Nikolai Ruhe Avatar answered Oct 22 '22 02:10

Nikolai Ruhe