UICollectionView
으로 무한 스크롤을 구현하고 싶습니다.UICollectionView로 무한 스크롤
//detect the bottom and add new data
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView.contentOffset.y >= (scrollView.contentSize.height - scrollView.bounds.size.height)) {
[NSObject cancelPreviousPerformRequestsWithTarget:self];
NSLog(@"%s",__PRETTY_FUNCTION__);
//ensure that the end of scroll is fired.
[self performSelector:@selector(scrollViewDidEndScrollingAnimation:) withObject:nil afterDelay:0.3];
}
}
-(void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
currentPage+=1;
// First figure out how many sections there are
NSInteger lastSectionIndex = [self.collectionView numberOfSections] - 1;
NSInteger lastItemIndex = [self.collectionView numberOfItemsInSection:lastSectionIndex] - 1;
NSIndexPath *pathToLastItem = [NSIndexPath indexPathForItem:lastItemIndex inSection:lastSectionIndex];
[Flickr searchFlickrForTerm:_searchBar.text page:currentPage completionBlock:^(NSString *searchTerm, NSArray *results, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self.searchResults[searchTerm] addObjectsFromArray:results];
[self.collectionView reloadData];
[_collectionView scrollToItemAtIndexPath:pathToLastItem atScrollPosition:UICollectionViewScrollPositionTop animated:YES];
});
}];
}
문제 scrollViewDidEndScrollingAnimation
때 방법 scrollToItemAtIndexPath:
실행될 때마다 트리거이다. 결과적으로, 나는 연속 슬라이드 쇼를 본다.
다른 지연으로 dispatch_after
을 사용하려고했지만 도움이되지 않습니다.
내가 알고있는 것처럼,있는 ScrollView는 contentSize
[self.collectionView reloadData];
후 어떻게 그것을 해결하기 위해의 업데이트하지 않는 이유는 무엇입니까?
안녕하세요, 혹시이 해결책을 찾았습니까? 그것은 내 애플 리케이션에 필요한 것처럼 보인다. –
@ JuanGonzález 불행히도 없습니다. – Shmidt
@ JuanGonzález 아래 나의 대답을 참조하십시오. – iwasrobbed