0

我使用 UICollectionView 从 instagram 获取一组图像,但是当我到达页面底部时,我想加载过去的图像。但是,我确实收到了过去的图像,因为它们已登录到控制台但没有出现在屏幕上。

这是我检索图像的代码:

- (void)nextInstagramPage:(NSIndexPath *)indexPath{
NSDictionary *page = self.timelineResponse[@"pagination"];
NSString *nextPage = page[@"next_url"];

[[InstagramClient sharedClient] getPath:[NSString stringWithFormat:@"%@",nextPage] parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    self.timelineResponse = responseObject;
    [self.collectionView reloadData];
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Failure: %@", error);
}];

}

这是我检测用户何时到达屏幕底部的代码:

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath{

[self nextInstagramPage:indexPath];

}

编辑:我发现collectionview是uiscrollview的一个子类,那么我将如何正确实现一个具有索引路径的方法来检测滚动视图的底部!

4

1 回答 1

0

With in your code i am making 2 assumptions, that you have an array of data to run parallel with your ui collection view and the delegate/datasource methods. you would notice at least these two methods in your code.

– collectionView:numberOfItemsInSection:
– collectionView:cellForItemAtIndexPath:

the first one tells you how many items/cells/squares you see in your ui collection view, the second makes you create what the item/cell/square will look like.

In the first method you told the uicolelction view how many there were, with in the cellforitem you should test "is this the last image" if it is the last image then download more images, if it is not the last image then continue as if nothing happened

Edit:

[[self entries] count]

you had that, now with in cell for row at index path do

if ( indexpath.item == ([[self entries] count] - 1) ) {
   // download more data and add it to the 'entries' array
}
于 2013-07-26T22:20:55.660 回答