Why is the delegate [[UIApplication sharedApplication]]; return null object

I have an iphone application with several views and corresponding controllers and xib files. In the controller for the first loaded view, I try to access the delegate for the application, but the returned object is nil

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

Any ideas why this will be zero?

+4
source share
1 answer

Because it is not installed yet. A UIApplication delegate is usually created and installed from the nib file of MainWindow. If you go to it before the nib is fully loaded (for example, the init method in the controller in the same column), it is zero.

+8
source

Source: https://habr.com/ru/post/1286284/


All Articles