Thanks
Thanks

Reputation: 40329

How can I access an outlet from my controller class in the app delegate class?

I want to change an image of an UIImageView from the applicationDidFinishLaunching method of the app delegate class. But I am afraid that this class doesnt know much about the controller outlet. What must I do in this case?

Upvotes: 0

Views: 354

Answers (2)

Jordan
Jordan

Reputation: 21760

You have to define the ViewController that the UIImageView is on, to the AppDelegate Class, so the applicationDidFinishLaunching can reference it.

In the AppDelegate add @class whateverViewController before the interface statement, and define the instance.

#import <UIKit/UIKit.h>

@class WhateverViewController;

@interface WebDemoAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    WhateverViewController *whateverViewController;
}

Now your app has a reference to whateverViewController. You can then call a method in whateverViewController to change the UIImageView or set the UIImageView directly. Of course this assumes that the whateverViewController is instantiated (e.g. alloc/init or loaded from nib); before you try to set anything, it must exist.

Upvotes: 2

Eric Petroelje
Eric Petroelje

Reputation: 60498

You would probably need to put an outlet for your UIImageView or its controller in your application delegate to make it accessible there.

Upvotes: 0

Related Questions