collectionviewとviewcontrollerの間のサイクルを保持すると考えられるため、ViewControllerを破壊するのに問題があります。私はcollectionviewを弱い変数にしようとしましたが、viewviewrollerにcollectionviewを追加しようとするたびにゼロになっています。コレクションビューを弱くするのではなく、別のルートがあれば、私はそれにもオープンしています。collectionviewで保持サイクルを取り除く方法
weak var table = UICollectionView(frame: CGRect(x: 0, y: 0, width: 0, height: 0), collectionViewLayout: UICollectionViewFlowLayout())
weak var customFlowLayout = UICollectionViewFlowLayout() //default cell spacing is 10
table?.frame = CGRect(x: 0, y: 50, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
table?.isHidden = true
table?.backgroundColor = UIColor.white
table?.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "customCellIdentifier")
table?.dataSource = self
table?.delegate = self
//table.rowHeight = CGFloat(100)
customFlowLayout?.minimumLineSpacing = 5 //default is 10
table?.collectionViewLayout = customFlowLayout!
self.view.addSubview(table!) //this is the line that breaks every time
どのようにViewControllerを破棄しようとしていますか? – atreat
コレクションビューは問題ではありません。問題は、ビューコントローラへのダイレクトリファレンスを保持しているときに、ビューコントローラを指定できないことです。私はあなたがどこかでそれをすると確信しています。 – Luzo