Question

Situation:
I am using the "Navigation Based Application" project template. And my root view controller (UIViewController) needs to call a method of the app delegate.

Question:
How do I call a method of the app delegate from a UIViewController?

Was it helpful?

Solution

[[[UIApplication sharedApplication] delegate] someMethod];

Or in applicationDidFinishLaunching: set a static member that is returned by a static method of your delegate class.

+(id) shared { return sAppDelegate; }
-(void) applicationDidFinishLaunching:(UIApplication *)a { sAppDelegate = self; }

Or just use a global without the wrapper.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top