I saved a picture to NSData with UserDefaults and now want it to be retrieved in a tableview cell.
Here is what I put in the ViewDidLoad of the TableView.m
NSData *imageData;
imageData = [NSKeyedArchiver archivedDataWithRootObject:yourUIImage];
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"image"];
And here is what I put in the TableView cellforRowatIndex
cell.imageView.image = [UIImage imageWithData:@"bild"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
However when I start the programe I get an EXC_BAD_ACCESS Error at the cell.imageView.image line together with a “incompatible pointer types sending “NSString*” to paramater of type “NSData*””
Here is btw how I save the image in the first place:
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"image"] == nil) {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
NSData *imageData;
UIImage *yourUIImage;
imageData = [NSKeyedArchiver archivedDataWithRootObject:yourUIImage];
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"image"];
Use
NSKeyedUnarchiveras a counterpart toNSKeyedArchiverlike this: