저는 Objective-C에 매우 익숙하며 초보자 문제가 있습니다. 나는 사진 갤러리처럼 행동해야하는 영역을 가진 응용 프로그램을 가지고 있습니다. 사용자가 카메라 롤에서 사진을 선택하면 사진이 UIImageViews에 표시됩니다. 내가 선택한 이미지를 저장하려고합니다. 9 개의 UIImageView가 있고 문제는 각 UIImageView에 대해 다른 사진을 선택하고 닫고 다시 실행하면 나머지 8 개의 UIImageViews는 첫 번째 이미지보기에 저장된 사진을 표시합니다. 차라리 그들 모두보다 같은 사진을 표시, 내가 올바른 사진을 표시 할 UIImageViews를 얻기 위해 변경할 필요가 무엇인지 알아 내려고 노력하고있어iOS : 사진 저장 문제
- (NSString *)dataFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(
NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return [documentsDirectory stringByAppendingPathComponent:kFilename9];
}
- (void)applicationDidEnterBackground:(UIApplication*)application {
NSLog(@"Image on didenterbackground: %@", imageView);
self.imageData = [NSData dataWithData:UIImagePNGRepresentation(imageView.image)];
self.imageData = [NSData dataWithData:UIImagePNGRepresentation(imageView2.image)];
self.imageData = [NSData dataWithData:UIImagePNGRepresentation(imageView3.image)];
self.imageData = [NSData dataWithData:UIImagePNGRepresentation(imageView4.image)];
self.imageData = [NSData dataWithData:UIImagePNGRepresentation(imageView5.image)];
self.imageData = [NSData dataWithData:UIImagePNGRepresentation(imageView6.image)];
self.imageData = [NSData dataWithData:UIImagePNGRepresentation(imageView7.image)];
self.imageData = [NSData dataWithData:UIImagePNGRepresentation(imageView8.image)];
self.imageData = [NSData dataWithData:UIImagePNGRepresentation(imageView9.image)];
[self.imageData writeToFile:[self dataFilePath] atomically:YES];
NSLog(@"The image is: %@", [[imageView image] description]);
NSLog(@"dataFilePath is: %@", [self dataFilePath]);
}
- (void)viewDidLoad
{
NSString *filePath = [self dataFilePath];
NSLog(@"FilePath: %@", filePath);
NSLog(@"Image: %@", imageView);
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
NSData *vdlData = [[NSData alloc] initWithContentsOfFile:filePath];
imageView.image = [[UIImage alloc] initWithData:vdlData];
imageView2.image = [[UIImage alloc] initWithData:vdlData];
imageView3.image = [[UIImage alloc] initWithData:vdlData];
imageView4.image = [[UIImage alloc] initWithData:vdlData];
imageView5.image = [[UIImage alloc] initWithData:vdlData];
imageView6.image = [[UIImage alloc] initWithData:vdlData];
imageView7.image = [[UIImage alloc] initWithData:vdlData];
imageView8.image = [[UIImage alloc] initWithData:vdlData];
imageView9.image = [[UIImage alloc] initWithData:vdlData];
}
UIApplication *app = [UIApplication sharedApplication];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidEnterBackground:)
name:UIApplicationDidEnterBackgroundNotification
object:app];
[super viewDidLoad];
}
: 여기에 내가 함께 일하고 있어요 코드입니다. 이것은 아마도 간단한 수정이지만, 도움을 주시면 대단히 감사하겠습니다.
vdlData ...에 저장된 동일한 이미지를 사용하여 각 imageView를 할당하고 하나의 경로 (dataFilePath)에 저장하기 전에 각 이미지를 동일한 변수에 저장 (서로 덮어 쓰기)하고 있는지 확인 했습니까? – David
오우 와우, 내가 어떻게 그리웠 니? 고맙습니다. 모든 변수를 하나의 경로에 저장하는 것이 좋을까요? 아니면 각 변수마다 다른 경로를 사용해야합니까? – John
여기 나는 대답으로 만들 것이다. – David