Reputation: 69
I have been trying to save an image that the user selected. Here is my save code:
-(IBAction)save123456 {
NSUserDefaults *myname = [NSUserDefaults standardUserDefaults];
[myname setObject:noteview.image forKey:@"name"];
}
That seems to be working but let me know if i should change anything. now here is my load code.
-(IBAction)load123456 {
NSUserDefaults *myname = [NSUserDefaults standardUserDefaults];
NSString *tempstring = [myname stringForKey:@"name"];
noteview.image = tempstring;
}
When i click the load button the image just goes away. What is wrong.
I am connecting every thing via touch up incised, Does that matter?
Thanks!!!
Upvotes: 0
Views: 679
Reputation: 89509
this line:
noteview.image = tempstring;
is assigning a "NSString
" to what should be a "UIImage
".
EDIT: and now that I realize what you're doing, you can not save a UIImage to a simple plist database like user defaults.
You need to either save the file separately and then save and load the path to the file, or you need to save and load the raw data (i.e. "NSData
") of the image to user defaults.
p.s. your choice of variable names is confusing. Instead of "myname", use "myDefaults" and instead of "tempname", use "nameImage" (i.e. more descriptive and understandable things).
Upvotes: 1