Skip to content

Commit 8639155

Browse files
committed
Clear the collection view cell scene on reuse
1 parent 2c16815 commit 8639155

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

SolarSystem/PlanetCollectionViewController.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ class PlanetDataSource: NSObject, UICollectionViewDataSource {
120120
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
121121
let planet = planets[indexPath.row]
122122
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "planetCell", for: indexPath) as! PlanetCell
123-
124123
let sceneString = "art.scnassets/\(planet.name).scn"
125124
let scene = SCNScene(named: sceneString)!
126125
cell.sceneView.scene = scene
@@ -138,4 +137,9 @@ class PlanetDataSource: NSObject, UICollectionViewDataSource {
138137

139138
class PlanetCell: UICollectionViewCell {
140139
@IBOutlet var sceneView: SCNView!
140+
141+
override func prepareForReuse() {
142+
sceneView.scene = nil
143+
}
144+
141145
}

0 commit comments

Comments
 (0)