0

APIからデータをダウンロードする私のアプリケーションにセクションが1つしかないコレクションビューがあります。ページネーションがあり、コレクションビューにローディングフッターを追加しようとしています。ヘッダーは正常に表示されます。私はこのフッターのセルにUIActivityIndi​​catorViewとUILabelを持っています。最初の制限がトリガーされると、2つの要素がセルに存在しますが、2番目の制限がトリガーされると、UIActivityIndi​​catorViewは存在しません。UIActivityIndi​​catorViewが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() 
} 

セルがよくあります登録された

最初の制限がトリガされたときに何が起こる:

enter image description here

そして、第二と:@MaksymMusiienkoコメントに基づいて

enter image description here

+0

UIActivityIndi​​catorViewには、「hidesWhenStopped」というプロパティがあります。ヘッダーをデキューするため、正しく構成しなかった場合は以前の状態が使用されます。 'prepareForReuse'メソッドをオーバーライドして、アニメーションを開始することができます。 –

+0

ありがとう@MaksymMusiienko、私はあなたのコメントに私のポストベースに答えている。それがあなたが意味していたことを確認できますか? –

答えて

0

、私は仕事をしている、これを試してみましたスピナーのアニメーションをリセットします。

class loadingCell: BaseCell { 

    let activitySpinner: UIActivityIndicatorView = { 
     let spinner = UIActivityIndicatorView() 
     spinner.backgroundColor = .red 
     spinner.startAnimating() 
     spinner.frame = CGRect(x: 10, y: 20, width: 20, height: 20) 
     return spinner 

    }() 

    override func setupViews() { 
     super.setupViews() 

     backgroundColor = .yellow 

     let label = UILabel() 
     label.text = "hello" 
     label.frame = CGRect(x: 100, y: 20, width: 40, height: 20) 
     label.backgroundColor = .green 


     addSubview(activitySpinner) 
     addSubview(label) 

    } 

    override func prepareForReuse() { 
     super.prepareForReuse() 
     activitySpinner.startAnimating() 
    } 
} 
+0

はい。あなたが要素を読み込んでいるときに、このセルのみを表示している場合: それはあなたのために働いたのですか? –

+0

ちょっと魅力的です:) –

関連する問題