사용자가 카메라 롤에서 그림을 선택하고 UIImageView에 표시 할 수있는 앱이 있습니다. 나는 텍스트 필드에 텍스트를 저장하기 위해 보통이 방법을 사용하며 이미지에 대해서도 작동한다고 가정했지만 문제가 있습니다. 오류는 없지만 단순히 이미지를 저장하지는 않습니다.iOS : UIImageView에서 그림 저장
이 내가 사용하고 관련 코드 :
.H :
#define kFilename9 @"PGdata.plist"
...
- (NSString *)dataFilePath;
하는 .m : 당신은 먼저 PNG 또는 JPG에있는 UIImage을 변환해야
- (NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:kFilename9];
}
- (void)applicationDidEnterBackground:(NSNotification *)notification {
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:image.image];
[array writeToFile:[self dataFilePath] atomically:YES];
}
- (void)viewDidLoad
{
...
NSString *filePath = [self dataFilePath];
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
image.image = [array objectAtIndex:0];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:app];
[super viewDidLoad];
}
최고 대단히 감사합니다. – John