loswerden Ich habe Probleme, Viewcontrollers zu zerstören, was ich glaube, ein Retain-Zyklus zwischen einer Collectionview und dem Viewcontroller zu sein. Ich habe versucht, die collectionview zu einer schwachen Variable zu machen, aber ich bekomme jetzt nil, wenn ich versuche, die viewsammlung dem viewcontroller hinzuzufügen. Wenn es eine andere Route zum Versuch gibt, anstatt die Sammlung zu schwächen, bin ich auch dafür offen.Wie man Retain-Zyklus mit 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
Wie versuchen Sie ViewControllers zu zerstören? – atreat
Sammlungsansicht sollte kein Problem sein. Problem ist, wenn Sie den direkten Verweis auf den View-Controller halten, dann kann der View-Controller nicht deaktiviert werden. Ich wette, du machst das irgendwo. – Luzo