当我将一个动作发送到MyController类时,我试图改变UIWindow的背景颜色。然而,UIWindow驻留在AppDelegate类中,因此我无权访问该变量以使用
修改它window.backgroundColor = [UIColor theColor];
MyController中的。这是MyController.m的代码:
@implementation MyController - (IBAction)sliderChanged:(id)sender { //want to call some method to change the UIWindow background color } @end
以下是AppDelegate.h的代码:
@interface AppDelegate : NSObject { UIWindow *window; } - (void)changeColorToRed:(int)r Green:(int)g Blue:(int)b; @property (nonatomic, retain) IBOutlet UIWindow *window; @end
我试图在AppDelegate类中实现一个方法changeColorToRed ...因为该方法可以访问变量window
,但我无法从MyController中的sliderChanged
方法调用它。
如何从其他类修改UIWindow *窗口?
答案 0 :(得分:12)
[UIApplication sharedApplication].delegate.window.backgroundColor = [UIColor myColor];
如果只有一个窗口,
[UIApplication sharedApplication].keyWindow.backgroundColor = [UIColor myColor];
答案 1 :(得分:0)
我想你可以:
在包含窗口变量
的类中创建一些静态方法或
将窗口变量传递给新类。