开发者

Application crash when change appDelegate variable

My Application was crash when i update my AppDelegate varibale. Am i declare the object in wrong way or UIColor not eligible to passing like this?

In AppDelegate.h i declare 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];
}

But the application was crash after i pressed several time the button to update myColor. Can any expert point out which part goes wrong?


Did you get any warning at this line? [sender backgroundColor];

If so, Instead of using [sender backgroundColor];

use,

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜