저는 UICollectionView
입니다. 여기 내 MainBundle
에서 몇 장의 사진을 보여주고 있습니다. 이 사진의 위치 또는 디렉토리는 SQLite
데이터베이스에 저장됩니다. segue
을 사용하고 있습니다. 문제는 이미지 링크를 detailsViewController
으로 보내려고하면 링크를 보내지 않는 것입니다.UICollectionViewCell이 다른 viewController에 데이터를 보내고 있습니다.
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
selectedPhotoIndex = indexPath.row;
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"PhotoDetailsViewController"])
{
PhotoDetailsViewController *photoDetailsViewController = [segue destinationViewController];
PhotoProperty *pProperty = [self.arrayOfPhotos objectAtIndex:selectedPhotoIndex];
[photoDetailsViewController setImagePath:pProperty.link];
//selectedPhotoIndex = 0;
}
}
하지만 밖으로 segue.identifier
에 코드를 넣어 경우는 detailsViewController
에 대한 링크를 보낼 수 있습니다.
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
PhotoDetailsViewController *photoDetailsViewController = [segue destinationViewController];
PhotoProperty *pProperty = [self.arrayOfPhotos objectAtIndex:selectedPhotoIndex];
[photoDetailsViewController setImagePath:pProperty.link];
//selectedPhotoIndex = 0;
}
그러나 여기에 문제가
, 그것은 어떤 경우 이전 링크의 참조를 유지하고 내가 선택한 엄지 라인의 이미지를 다시 활용할 수있는 올바른 이미지를 표시 할 수 있습니다. 나는이 대안들을 시도하지만 운은 없다. 하나는 내 문제를 이해하고 모든 솔루션이 나와 함께 공유하시기 바랍니다가있는 경우- (void)viewDidLoad
{
[super viewDidLoad];
self.sQLite = [[SQLite alloc] init];
[self.sQLite callDataBaseAndPhotoTableMethods];
self.arrayOfPhotos = [[NSMutableArray alloc] init];
self.arrayOfPhotos = [self.sQLite returnDataFromPhotoTable];
self.photoCollectionView.delegate = self;
self.photoCollectionView.dataSource = self;
}
/*------------ It takes the original size of photo and make it's size smaller (Down)------------*/
- (UIImage*)imageWithImage:(UIImage*)image scaledToSize:(CGSize)newSize;
{
UIGraphicsBeginImageContext(newSize);
[image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
/*------------ It takes the original size of photo and make it's size smaller (Down)------------*/
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.arrayOfPhotos count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cell = [self.photoCollectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
self.photoProperty = [self.arrayOfPhotos objectAtIndex:indexPath.row];
// NSLog(@"id %d", photoProperty.idNumPHOTO);
// NSLog(@"name %@", photoProperty.name);
// NSLog(@"links %@", photoProperty.link);
NSData *imageData = [NSData dataWithContentsOfFile:photoProperty.link];
UIImage *originalImage = [[UIImage alloc] initWithData:imageData];
// This is the size where I get from the Cell UIImageView hight & wodth
CGSize size = CGSizeMake(36.0f, 51.0f);
UIImage *thumbNailImage = [self imageWithImage:originalImage scaledToSize:size];
cell.imageView.image = thumbNailImage;
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
return cell;
}
:
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"PhotoDetailsViewController"])
{
PhotoDetailsViewController *photoDetailsViewController = [segue destinationViewController];
CustomCell *cell = (CustomCell *) sender;
NSIndexPath *indexPath = [self.photoCollectionView indexPathForCell:cell];
//NSLog(@"indexPath %@",indexPath);
PhotoProperty *pProperty = [self.arrayOfPhotos objectAtIndex:indexPath.row];
[photoDetailsViewController setImagePath:pProperty.link];
}
}
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"PhotoDetailsViewController"])
{
CustomCell *cell = (CustomCell *) sender;
NSIndexPath *indexPath = [self.photoCollectionView indexPathForCell:cell];
int num = indexPath.row %10;
NSLog(@"num %i", num);
PhotoDetailsViewController *photoDetailsViewController = (PhotoDetailsViewController *)[segue destinationViewController];
PhotoProperty *pProperty = [self.arrayOfPhotos objectAtIndex:num];
[photoDetailsViewController setImagePath:pProperty.link];
}
}
여기 내 전체 코드입니다. 고급에 많이 감사드립니다.
좋은 하루 보내십시오.
답해 주셔서 감사합니다. 이제 완벽하게 작동합니다. :) – Tulon