5
votes

I am trying to change the background color of a UIWindow when an action is sent to the class MyController. However the UIWindow resides in the AppDelegate class so I don't have access to the variable to modify it using

window.backgroundColor = [UIColor theColor];

in MyController. Here is the code for MyController.m:

@implementation MyController
- (IBAction)sliderChanged:(id)sender {
 //want to call some method to change the UIWindow background color
}
@end

And here is the code for AppDelegate.h:

@interface AppDelegate : NSObject  {
    UIWindow *window;
}

- (void)changeColorToRed:(int)r Green:(int)g Blue:(int)b;

@property (nonatomic, retain) IBOutlet UIWindow *window;

@end

I tried to implement a method changeColorToRed... in the AppDelegate class because that method has access to the variable window, but I had no way to call that from the sliderChanged method in MyController.

How can I modify the UIWindow * window from another class?

2

2 Answers

13
votes
[UIApplication sharedApplication].delegate.window.backgroundColor = [UIColor myColor];

If there's only 1 window,

[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor myColor];
0
votes

I think you could either:

Make some static method in the class containing the window variable

or

Pass the window variable to the new class.