APIからデータをダウンロードする私のアプリケーションにセクションが1つしかないコレクションビューがあります。ページネーションがあり、コレクションビューにローディングフッターを追加しようとしています。ヘッダーは正常に表示されます。私はこのフッターのセルにUIActivityIndicatorViewとUILabelを持っています。最初の制限がトリガーされると、2つの要素がセルに存在しますが、2番目の制限がトリガーされると、UIActivityIndicatorViewは存在しません。UIActivityIndicatorViewがCollectionViewフッターで消えます
考えてもらえますか?
セルのコード(BaseCellがINITをタップし、各時間にinit必要ないようにするだけのクラスです):
class loadingCell: BaseCell {
override func setupViews() {
super.setupViews()
backgroundColor = .yellow
let activity = UIActivityIndicatorView()
activity.backgroundColor = .red
activity.startAnimating()
activity.frame = CGRect(x: 10, y: 20, width: 20, height: 20)
let label = UILabel()
label.text = "hello"
label.frame = CGRect(x: 100, y: 20, width: 40, height: 20)
label.backgroundColor = .green
addSubview(activity)
addSubview(label)
}
}
収集デリゲートメソッド:
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
return CGSize(width: SCREENW, height: 50)
}
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if kind == UICollectionElementKindSectionFooter {
let loadingFooterView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionFooter, withReuseIdentifier: loadingCell, for: indexPath)
return loadingFooterView
}
return UICollectionReusableView()
}
セルがよくあります登録された
最初の制限がトリガされたときに何が起こる:
そして、第二と:@MaksymMusiienkoコメントに基づいて
UIActivityIndicatorViewには、「hidesWhenStopped」というプロパティがあります。ヘッダーをデキューするため、正しく構成しなかった場合は以前の状態が使用されます。 'prepareForReuse'メソッドをオーバーライドして、アニメーションを開始することができます。 –
ありがとう@MaksymMusiienko、私はあなたのコメントに私のポストベースに答えている。それがあなたが意味していたことを確認できますか? –