私は、Firebaseデータベース内の子に対応するセルを持つCollectionViewを持っています。私の問題は、私が別のビューにセグをしてから、Segueを戻すとCollectionViewセルがなくなったことです。コレクションビューのセルを表示したままに戻す方法
私はcellForItemAt機能を持っている:私はまだCollectionViewは、細胞を作成する方法を学習し、どのような表示が眠っているときに、プログラムが行う
for i in 0..<playerArrayList.count{
print(playerCollectionView.numberOfItems(inSection: 0))
//playerCollectionView.insertItems(at: [IndexPath(item: i, section: 0)])
let cell = playerCollectionView.cellForItem(at: IndexPath(item: i, section: 0)) as! PlayerCollectionViewCell
cell.tempUserName = playerArrayList[i]
cell.setupViews(parentSize: Int(self.playerCollectionView.frame.width), hostUID: self.currentUID, tempUserName: playerArrayList[i])
}
:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "playerItem", for: indexPath) as! PlayerCollectionViewCell
cell.setupViews(parentSize: Int(self.playerCollectionView.frame.width), hostUID: self.currentUID, tempUserName: playerArrayList[indexPath.item])
cell.layer.cornerRadius = 6
cell.layer.borderWidth = 2
return cell
}
私はまた、別のコードsnippitを持っていますしかし、私は自分の問題は、cellForItemAt関数は、ビューが最初に作成されたときにすべてのセルを作成し、その後には発生しないと考えています。 これは確かですが、最初にビューを作成すると3つのセル(データベース内に正確に何人の子供がいるか)が同じビューに戻るときにセルがないためです。 私はすべてのセルを削除してリメイクすることでこれを解決しようとしました。
:私はまた、細胞を作成するために、これを使用して試してみましたTerminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of items in section 0. The number of items contained in an existing section after the update (3) must be equal to the number of items contained in that section before the update (3), plus or minus the number of items inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of items moved into or out of that section (0 moved in, 0 moved out).'
:
playerCollectionView.insertItems(at: [IndexPath(item: i, section: 0)])
しかし、これは私にエラーを与える:コードスニペットで は、あなたはコメント行を見ることができます
しかし私は同じエラーを取得します。ビューに戻ると、セルをどのように再作成できますか?
を行うことができますリロード必要がある場合は?元のView Controllerの新しいインスタンスに進むつもりはありませんか? – Paulw11
@ Paulw11私が切り替えている2つのビューは同じスタックにあるため、新しいインスタンスではないと確信しています。 https://drive.google.com/file/d/0B5SQeKTVAsVbSEFweEw0dURVejQ/view?usp=sharing segue自体はsegueingする前に操作を実行する必要があるため、コントローラを表示するコントローラではなく、コントローラを表示するビューコントローラからのものです。 – mike
ナビゲーションコントローラで「戻る」ボタンを使用していない場合は、巻き戻しセグを使用する必要があります。そうしないと、View Controllerの新しいインスタンスが継続的にプッシュされます。新しいインスタンスを作成しているときに、複数回呼び出された場合は、 'viewDidLoad'にログステートメントまたはブレークポイントを入れてください。 – Paulw11