I have a star rating view which uses custom class RateView.m and .h files to show the star rating image and a label to show how much rating is given as given below:
Now when the rating is clicked, the selected image is shown and when unselected another image is shown.
This Rateview calls a delegate when that rateview is clicked
- (void)rateView:(RateView *)rateView ratingDidChange:(float)rating {
self.statusLabel.text = [NSString stringWithFormat:@"Rating: %0.1f/5.0", rating];
NSString *valueToSave = self.statusLabel.text;
// self.rateView.fullSelectedImage = [UIImage imageNamed:@"yellow-rating.png"];
// UIImage *contactImage = self.rateView.fullSelectedImage;
[[NSUserDefaults standardUserDefaults] setObject:valueToSave forKey:@"ratingSelected"];
// [[NSUserDefaults standardUserDefaults] setObject:UIImagePNGRepresentation(contactImage) forKey:@"image"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
In viewwillappear method it is as shown:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSString *savedValue = [[NSUserDefaults standardUserDefaults] stringForKey:@"ratingSelected"];
self.statusLabel.text = savedValue;
NSData *imageData = [[NSUserDefaults standardUserDefaults] objectForKey:@"image"];
// NSLog(@"imagedata is %@",imageData);
UIImage *contactImage = [UIImage imageWithData:imageData];
NSLog(@"contactImage is %@",contactImage);
// self.rateView.fullSelectedImage = contactImage;
self.rateView.fullSelectedImage = [UIImage imageNamed:@"yellow-rating.png"];
}
Now the issue is i can see the label with correct rating,but the image is not saved using userdefault.
How to also save the image using userdefault in my case.