Non riesco a salvare un'immagine utilizzando NSUserDefaults e crash la mia app e ho classe personalizzata utilizzato anche UserInfo che ha usatoiPhone: come posso archiviare UIImage usando NSUserDefaults?
-(void)encodeWithCoder:(NSCoder *)encoder
{
NSData *imageData = UIImagePNGRepresentation(categoryImage);
[encoder encodeObject:categoryName forKey:@"name"];
[encoder encodeObject:imageData forKey:@"image"];
}
- (id) initWithCoder: (NSCoder *) decoder e userInfo.categoryImage è variabile UIImage.
motivo: '- [UIImage encodeWithCoder:]: selettore non riconosciuto inviato ad esempio 0x7676a70'
userInfo = [[UserInfo alloc] init];
userInfo.categoryName = categoryName.text;
NSLog(@"Category Name:--->%@",userInfo.categoryName);
userInfo.categoryImage = image;
appDelegate.categoryData = [[NSMutableDictionary dictionaryWithObjectsAndKeys:
userInfo.categoryName, @"name",userInfo.categoryImage,@"image", nil] mutableCopy];
[appDelegate.categories addObject:appDelegate.categoryData];
NSLog(@"Category Data:--->%@",appDelegate.categories);
[appDelegate.categories addObject:userInfo.categoryName];
[appDelegate.categories addObject:userInfo.categoryImage];
[self saveCustomObject:userInfo.categoryName];
[self saveCustomObject:userInfo.categoryImage];
-(void)saveCustomObject:(UserInfo *)obj
{
appDelegate.userDefaults = [NSUserDefaults standardUserDefaults];
NSData *myEncodedObject = [NSKeyedArchiver archivedDataWithRootObject:obj];
[appDelegate.userDefaults setObject:myEncodedObject forKey:@"myEncodedObjectKey"];
}
Così Please help me come posso memorizzare e recuperare UIImage utilizzando nsusedefaults ???
Il saveCustomObject difficilmente può funzionare, perché memorizza ogni oggetto dato per la stessa chiave. – Davyd