我使用UICollectionView AFNetworking 2从Web服务异步加载图像.它工作得很好.但是,如何实现自动滚动(当用户到达页面底部或靠近页面时,调用API以获取更多单元格).
我见过很多例子,但似乎没有最好的做法.例如,一个教程建议使用scrollViewDidScroll,但每次滚动视图时都会调用它.这是正确的实施吗?
这是我的细胞创建代码:
func collectionView(collectionView: UICollectionView!,cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! { let cell = collectionView.dequeueReusableCellWithReuseIdentifier(cellIdentifier,forIndexPath: indexPath) as UICollectionViewCell let offer = self.offers[indexPath.row] var cellImageView = cell.viewWithTag(100) as UIImageView let requestURL = NSURLRequest(URL: offer.largeImageURL) cellImageView.setImageWithURLRequest( requestURL,placeholderImage:placeholderImage,success: { (request:NSURLRequest!,response:NSHTTPURLResponse!,image:UIImage!) in cellImageView.image = image },failure: { (request:NSURLRequest!,error:NSError!) in NSLog("GET Image Error: " + error.localizedDescription) } ) return cell }