1

UICollectionView用来显示从设备照片库加载的图像。我正在使用资产库来加载图像。当我滚动时UICollectionView,图像正在改变它们在集合视图中的位置(不重复)。因此,当我单击图像时,正在加载不同的图像。有什么帮助吗?

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

    UIImageView *GalleryImageView = (UIImageView *)[cell viewWithTag:100];
    url=@"";
    Document* doc = [galleryImages objectAtIndex:indexPath.row];
    GalleryImageView.contentMode = UIViewContentModeScaleAspectFill;
    url = doc.path;
    NSLog(@"%@",url);
    NSURL *referenceURL = [NSURL URLWithString:url];
    __block UIImage *returnValue = nil;
    [library assetForURL:referenceURL resultBlock:^(ALAsset *asset)
     {
         returnValue = [UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]];
         GalleryImageView.image = returnValue;
         returnValue = nil;
         documentID= [dbutil getDocumentIDbyPath:url];
         GalleryImageView.tag = documentID;

     }
            failureBlock:^(NSError *error)
     {
         NSLog(@"error : %@", error);
     }];



    return cell;
    }
4

0 回答 0