Ich habe eine UITableViewCell
Unterklasse, die eine Bool
enthält. Diese Eigenschaft sollte beibehalten werden (während die Zelle sichtbar ist), jedoch scheint es so eingerichtet zu sein, dass, wenn collectionView:cellForItemAtIndexPath:
aufgerufen wird, die Eigenschaft zurückgesetzt wird. BeispielPersist UITableViewCell Unterklasse Eigenschaft
class CellClass: UITableViewCell {
var someBool: Bool = false
func doSomethingWithBool() {
if someBool {
thing1()
someBool = false
} else {
thing2()
someBool = true
}
}
}
class CollectionView: UICollectionView {
@IBAction func buttonPressed() {
// Do some things
// cellForItemAtIndexPath called again here
self.collectionView?.reloadItemsAtIndexPaths(paths)
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CellClass
// Everything else
if collectionViewProperty {
// This doesn't work right because someBool is reset to false
cell.doSomething()
}
return cell
}
Muß ich someBool
in einer init
Methode setzen müssen? Was ist der richtige Weg dies zu gestalten?
Hat die doSomething() Funktion ändern someBool außer Kraft setzen? – sebenalern
Ja, es ändert einigeBool – Ja5onHoffman