나는 UIImageView
중 하나와 함께 매우 이상한 버그를 발견했습니다. 항목을 나열하는 UITableView
이 있고 각 셀은 항목입니다. 각 항목 셀에는 축소판 이미지, 제목 및 부제목이 있습니다. 시뮬레이터와 iPhone에서 모든 셀의 미리보기 이미지를 완벽하게 표시 할 수 있습니다.UIImageView는 시뮬레이터에서 이미지를 보여 주지만 iPhone에서는 보이지 않습니다.
특정 셀을 두드리면 세그웨이가 해당 VC에 접속하여 큰 이미지와 아이템에 대한 추가 정보를 보여줍니다. 시뮬레이터에서 이미지를로드 할 수 있었지만 iPhone에서는 공백 인 것입니다. UIImageView
.
이것은 시뮬레이터에서 보이는 방법입니다.
그리고 내 세부 VC : 나는이 항목에 대한 자세한 내용을 표시하는 라벨을 추가 할 경우하단의 파란색보기, 그리고 오렌지는 UIImageView
입니다 '항목 세부 정보'만 말하는 맞춤 이미지가 표시됩니다. 그 중 하나, 또는 큰 내 UImageView
그리고 그것을 움직일 수 있습니다 (그리고 아래로 해제) 최대 애니메이션 것입니다.
이제 문제는 - 내 VC에서 내 세부 VC로 연결될 때, UIImageView
은 아이폰에서 그냥 비어 있습니다. 그것은 시뮬레이터에서 완벽하게 작동하지만 오른쪽 이미지 등을 전달합니다. 여기
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"showItemDetails"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
ItemDetailViewController *itemDetailVC = segue.destinationViewController;
Item *item = [self.fetchedResultsController objectAtIndexPath:indexPath];
if(item)
{
itemDetailVC.pictureImage = [UIImage imageWithContentsOfFile:item.photoURL];
}
}
}
내 항목이 코어 데이터를 사용하여 저장됩니다. photoURL
은 전체 이미지를 핵심 데이터로 저장하지 않기 때문에 내 앱의 문서 디렉토리에있는 사진의 URL이며 실적을 위해 참조로 사용됩니다.
"unwind"segue에서 다른 VC의 데이터를 가져 오는 코드의 일부입니다. 내 세부 VC에서
- (IBAction)saveItem:(UIStoryboardSegue *)segue
{
ManageItemViewController *manageItemVC = (ManageItemViewController *)segue.sourceViewController;
NSMutableDictionary *itemInfo = [[NSMutableDictionary alloc] init];
...
// write the original photo to a file and keep an URL to it that we pass to Core Data
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(manageItemVC.pictureImage)];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0]; //Get the docs directory
NSString *fileName = [NSString stringWithFormat:@"%lf.png", [[NSDate date] timeIntervalSince1970]];
NSString *filePath = [documentsPath stringByAppendingPathComponent:fileName]; //Add the file name
[imageData writeToFile:filePath atomically:YES]; //Write the file
[itemInfo setObject:filePath forKey:CD_ITEM_PHOTOURL_PROPERTY];
...
[self saveItemToCoreData:[itemInfo copy]];
}
이 내가 큰 UIImageView
에 보내는 UIImage
를로드 할 모든 것입니다.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(self.pictureImage) {
[self.pictureImageView setImage:self.pictureImage];
}
}
그리고 사용자가 (행 삭제) 항목을 삭제하는 경우 등 (이 코드는 내 테이블 VC에), 나는 또한, 내 문서 디렉토리에서 파일을 제거 : 나는 기록
- (void)deleteItemImageFromDevice:(NSString *)filePath
{
if(filePath)
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
if([fileManager removeItemAtPath:filePath error:&error]) {
NSLog(@"Image deleted from documents directory!");
} else {
NSLog(@"%@", error);
}
}
}
이것과 나는 시뮬레이터에서 어떤 에러도 얻지 못한다.
누구든지 여기에 어떤 문제가 있는지 알고 계십니까? 감사.
귀하의 질문에 답변 해 주셔서 +1합니다. 잘 했어.:) –