質問内容:
コレクションビューのprefetchを使って先読みするような
プログラムを書きたいのですが、そもそもprefetchItemsAtが
なぜかメソッドが呼ばれません
他にも何か記載が必要なんでしょうか、初心者で分からず・・
申し訳ないですが教えてください
よろしくお願いします。
以下ソースになります(テストで書いています)
import UIKit
class te: UIViewController,UICollectionViewDataSourcePrefetching,UICollectionViewDelegate,UICollectionViewDataSource {
@IBOutlet weak var collectionview: UICollectionView! let photolist:[String] = ["1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1"] override func viewDidLoad() { super.viewDidLoad() collectionview.dataSource = self collectionview.delegate = self collectionview.prefetchDataSource = self // Do any additional setup after loading the view. } /* // MARK: - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation override func prepare(for segue: UIStoryboardSegue, sender: Any?) { // Get the new view controller using segue.destination. // Pass the selected object to the new view controller. } */ func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return photolist.count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell:UICollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell",for: indexPath) print("koko:(indexPath)") return cell } func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) { print("Prefetch: (indexPaths)") }
}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/03/09 04:08
2020/03/09 04:17
2020/03/09 04:31
退会済みユーザー
2020/03/09 05:05
2020/03/09 05:12
2020/03/09 05:26
2020/03/09 06:19
2020/03/09 06:56
2020/03/09 07:36
2020/03/09 08:16