开发者

Application crash when change appDelegate variable

开发者 https://www.devze.com 2023-02-14 05:21 出处:网络
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?

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

精彩评论

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