在UICollectionView中使用分页选项显示图像

时间:2015-01-09 09:09:49

标签: ios uicollectionview

我在Instagram API中显示UICollectionView中的图像,有加载更多图像的分页选项,现在我的问题是当我获取下一页图像并重新加载我的UICollectionView时它不仅从第二页图像重新加载

这是我的代码

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
NSLog(@"%d",arrUrlImage.count);
return arrUrlImage.count;
}



 - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

NSString *identifier=@"cell";



UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];



UIImageView *imgView=(UIImageView*)[cell viewWithTag:100];


int indexValue = arc4random() % 6;
UIColor *color=[arrCellBGColor objectAtIndex:indexValue];
cell.backgroundColor=color;
[UIView animateWithDuration:2 animations:^{
    cell.backgroundColor=[UIColor clearColor];
} completion:NULL];
NSURL *url=[NSURL URLWithString:[arrUrlImage objectAtIndex:indexPath.row]];

[self downloadImageWithURL:url completionBlock:^(BOOL succeeded, UIImage *image) {

    if (succeeded) {
        imgView.alpha = 0;
        [UIView animateWithDuration:2 animations:^{
            imgView.alpha = 1;
        }];
        // change the image in the cell
        // cell.imageView.image = image;

        // cache the image for use later (when scrolling up)

        imgView.image=image;
    }
}];


if (indexPath.row==arrUrlImage.count-3) {
    NSLog(@"load more image.");
    NSString *nextPageUrl=[[arrMedia valueForKey:@"pagination"] valueForKey:@"next_url"];
    [arrMedia removeAllObjects];
    NSLog(@"%@",nextPageUrl);
    [self grabMedia:nextPageUrl];


}






return cell;
}

0 个答案:

没有答案