就像这样,所以如果遇到类似问题的人,你就可以这样做
所以这就是我在applicationdidfinishlaunching中放入的内容
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"image"] == nil) {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
}
这是我在
中写的内容(void)imagePickerController:(UIImagePickerController *) Picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSData *imageData;
UIImage *yourUIImage;
imageData = [NSKeyedArchiver archivedDataWithRootObject:yourUIImage];
[[NSUserDefaults standardUserDefaults] setObject:imageData forKey:@"image"];
yourUIImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissModalViewControllerAnimated:YES];}
答案 0 :(得分:1)
您正在序列化(存档)未初始化的变量。变量yourUIImage
已声明,但您从不为其分配任何内容。然后你尝试存档它。如果你很幸运,yourUIImage
只是nil
,但是如果你运气不好会因为整齐的垃圾指针而崩溃。
答案 1 :(得分:1)
这可能听起来很愚蠢,但你在设置对象后调用了[[NSUserDefaults standardUserDefaults] synchronize]
吗?