我通过以下代码从 iphone 中选择了一张图片:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self dismissViewControllerAnimated:YES completion:nil];
UIImage *pickedImg = (UIImage*)[info objectForKey:UIImagePickerControllerOriginalImage];
[self.photoBtn setBackgroundImage:pickedImg forState:UIControlStateNormal];
[[self.tblView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]].contentView addSubview:photoBtn];
data.img = pickedImg;
//data.img = nil;
[self.tblView reloadData];
}
然后通过此代码保存:
-(void)saveProfile {
data.firstName = firstName.text;
data.lastName = lastName.text;
data.phoneMob = phoneMob.text;
data.phoneHome = phoneHome.text;
data.emailOffice = emailOff.text;
data.emailPersonal = emailPers.text;
data.address = address.text;
data.company = company.text;
data.website = website.text;
//NSLog(data.img);
NSMutableData *pData = [[NSMutableData alloc]init];
NSString *path = [common saveFilePath];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:pData];
[data encodeWithCoder:archiver];
[archiver finishEncoding];
[pData writeToFile:path atomically:YES];
[self.navigationController popViewControllerAnimated:YES];
}
但是当我试图保存配置文件时,它会导致速度变慢。然后我尝试data.img = nil
了第一种方法。现在它没有缓慢和没有图像保存。如何用图像固定保存?