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];
精彩评论