开发者

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

开发者 https://www.devze.com 2022-12-30 22:21 出处:网络
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.

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?


[[[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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号