Last active
February 4, 2018 08:29
-
-
Save killev/b802c213a1e1a9d05853ca7b869bcc28 to your computer and use it in GitHub Desktop.
UICollectionView changes problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, UICollectionViewDataSource { | |
@IBOutlet weak var collectionView: UICollectionView! | |
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
return collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) | |
} | |
func numberOfSections(in collectionView: UICollectionView) -> Int { | |
return 1 | |
} | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
return array.count | |
} | |
var array : Array<Int> = [1,2,3] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
collectionView.register(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell") | |
collectionView.reloadData() | |
addItem(sender: nil) | |
addItem(sender: nil) | |
} | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
} | |
override func viewDidAppear(_ animated: Bool) { | |
super.viewDidAppear(animated) | |
} | |
@IBAction func addItem(sender: AnyObject?){ | |
array.append(10) | |
collectionView.insertItems(at: [IndexPath(row: 0, section: 0)]) | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment