开发者

Call AppDelegate Method from Class

开发者 https://www.devze.com 2023-01-03 18:39 出处:网络
Basically, I need to call a method in my AppDelegate from one of my view controller classes. Currently, I\'m doing the following:

Basically, I need to call a method in my AppDelegate from one of my view controller classes.

Currently, I'm doing the following:

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

[appDelegate doMethod];

And including the myAppDelegate.h at the top of the .m file of the class:

#import "myAppDelegate.h"

When I run it, everything works...

But I get the following warning:

warning 'myAppDelegate' may not respond to '-doMethod'

Is there another way that I should reference the app delegate?

Thanks for any help in advance.

EDIT: FIXED:

All I h开发者_如何学Pythonad to do was declare the method in the .h file of the AppDelegate:

-(void)doMethod;


adding to Marks comment. Is the -(void) doMethod; declared in the appDelegate header file and is the appDelegate.h file imported in the file you try to call the method from:)

Sorry should have put it in as an answer in the first place, so the question does not look unanswered :/

0

精彩评论

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