Calling the AppDelegate Method from the Class

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

I am currently doing the following:

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

[appDelegate doMethod];

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

#import "myAppDelegate.h"

When I run it, everything works ...

But I get the following warning:

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

Is there any other way that I should refer to the application delegate?

Thanks for any help in advance.

EDIT: FIXED:

All I had to do was declare the method in the .h file of the AppDelegate:

-(void)doMethod;

+6
objective-c iphone
source share
1 answer

Add Comment Marks. Whether declared -(void) doMethod; in the appDelegate header file and is the appDelegate.h file imported into the file you are trying to call the method :)

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

+4
source share

All Articles