UIImagePickerController Causes my app to crash!
        Posted  
        
            by Flafla2
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Flafla2
        
        
        
        Published on 2010-04-16T15:01:00Z
        Indexed on 
            2010/04/16
            15:03 UTC
        
        
        Read the original article
        Hit count: 606
        
In my app, a user can select an image, change the picture of a UIImageView to the new imge, and save the image to NSUserDefaults using NSKeyedArchiver. When the user selects the image the app immediately crashes! Here is my code -
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picker dismissModalViewControllerAnimated:YES];
    if ([[NSUserDefaults standardUserDefaults] integerForKey:@"PictureKey"] == 1) {
        UIImage *previmage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        [prevbutton setImage:previmage];
        NSData *previmagedata = [NSKeyedArchiver archivedDataWithRootObject:previmage];
        [[NSUserDefaults standardUserDefaults] setObject:previmagedata forKey:@"PrevImage"];
    } else if ([[NSUserDefaults standardUserDefaults] integerForKey:@"PictureKey"] == 2) {
        UIImage *nextimage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        [nextbutton setImage:nextimage];
        NSData *nextimagedata = [NSKeyedArchiver archivedDataWithRootObject:nextimage];
        [[NSUserDefaults standardUserDefaults] setObject:nextimagedata forKey:@"NextImage"];
    }else {
        UIImage *optionsimage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        [moreoptionsbutton setImage:optionsimage];
        NSData *optimagedata = [NSKeyedArchiver archivedDataWithRootObject:optionsimage];
        [[NSUserDefaults standardUserDefaults] setObject:optimagedata forKey:@"OptionsImage"];
    }
}
Thanks in advance!
© Stack Overflow or respective owner