我有兩個views.On我的第一視圖,我有一個自定義的button.By點擊該按鈕另一種觀點將與圖標創建library.by單擊該圖標圖標將設置爲1 view.i有值存儲到NSUser defaults.but圖標未設置。圖像不設置自定義按鈕
這裏是代碼:
視圖2:
-(IBAction)btnImage1Clicked:(id)sender{
NSString *[email protected]"NODE - BOOK_a.png";
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
if (standardUserDefaults) {
[standardUserDefaults setValue:img1 forKey:@"image1"];
[standardUserDefaults synchronize];
}
[img1 release];
[self dismissModalViewControllerAnimated:YES];
}
廠景:
-(void)viewWillAppear:(BOOL)animated{
NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
NSString *val = nil;
NSLog(@"val=%@",val);
NSLog(@"user default=%@",[standardUserDefaults valueForKey:@"image1"]);
if (standardUserDefaults)
val = [standardUserDefaults stringForKey:@"image1"];
NSLog(@"image name=%@",val);
UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@",val]];
stringWithFormat:@"%@",val]] forState:UIControlStateNormal];
[imageButton setBackgroundImage:image forState:UIControlStateNormal];
forState:UIControlStateNormal];
[[NSUserDefaults standardUserDefaults] setValue:@"" forKey:@"image1"];
}
我不知道你爲什麼在視圖2釋放'img1'當你不分配它。過度放置並不是一個好習慣。它可能會導致殭屍墜毀。 –