2017-10-12 4 views
0

私はiOS開発とSwiftにはとても新しいです。 配列から画像を取り込むUICollectionViewがあります。私の考えは最初10枚の画像を読み込み、ユーザがcollectionViewの一番下までスクロールさせてから、「more」ボタンを押すか、自動的に押すことで配列から次の10枚の画像をロードすることです。 これを行う最善の方法を提案できますか? 私のコードは次のとおりです。スイフト。ロードコレクションビューをn要素で

self.searches.insert(results, at: 0) 
override func collectionView(_ collectionView: UICollectionView, 
           cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
     //1 
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, 
                 for: indexPath) as! CatPhotoCell 
     // this methods takes one photo from searches array 
     let flickrPhoto = photoForIndexPath(indexPath: indexPath) 

     cell.imageView.image = flickrPhoto.thumbnail 
     cell.cat_name.text = flickrPhoto.title 

     return cell 
    } 

private extension CatsPhotosCollectionViewController { 
    func photoForIndexPath(indexPath: IndexPath) -> FlickrPhoto { 
     return searches[(indexPath as NSIndexPath).section].searchResults[(indexPath as IndexPath).row] 
    } 
} 
+0

ページネーションは、最後のセルまたは5番目から最後のセルが表示されている場合は 'willDisplayCellForItemAtIndexPath'、それ以上などをロードします。 – Brandon

答えて

1

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView){ //step 2 here }

1.Intially設定の配列を使用すると、上記の関数の中で好きな10と

2.Increase配列数をカウントし、collectionViewをリロードします。

+0

ソースの配列を意味しますか?コレクションビュー? –

関連する問題