Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call AppDelegate Method from Class

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 had to do was declare the method in the .h file of the AppDelegate:

-(void)doMethod;

like image 393
element119 Avatar asked Jun 12 '10 14:06

element119


People also ask

What is the difference between SceneDelegate and AppDelegate?

AppDelegate is responsible for handling application-level events, like app launch and the SceneDelegate is responsible for scene lifecycle events like scene creation, destruction and state restoration of a UISceneSession.

What is a AppDelegate class?

A set of methods to manage shared behaviors for your app.

Which method of AppDelegate is called first in iOS?

AppDelegate. UIViewController is allocated as the window's initial view controller. To make the window visible, makeKeyAndVisible method is called.


1 Answers

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 :/

like image 118
RickiG Avatar answered Nov 12 '22 04:11

RickiG