更改appDelegate变量时应用程序崩溃

时间:2011-03-01 06:53:55

标签: iphone objective-c cocoa-touch

当我更新AppDelegate varibale时,我的应用程序崩溃了。我是以错误的方式声明对象还是UIColor没有资格像这样传递?

在AppDelegate.h中,我声明了UIColor Object:

UIColor *myColor;

@property(nonatomic,retain) UIColor *myColor;

In my viewController i update the myColor when a button pressed.

-(IBAction) pressed:(id)sender{
    YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate];
    appDelegate.myColor = [sender backgroundColor];
}

但是我按下几次按钮来更新myColor后,应用程序崩溃了。任何专家都可以指出哪个部分出错了吗?

1 个答案:

答案 0 :(得分:0)

你在这条线上有任何警告吗? [sender backgroundColor];

如果是这样,而不是使用[sender backgroundColor];

使用,

UIButton *but=(UIButton *)sender;
appDelegate.myColor=[but backgroundColor];