我是初学者,我想根据用户是否想要添加更多单元格来更改集合视图中的单元格数量。我尝试做同样的事情,我做了表视图,但似乎没有用。无论我改变甲板阵列的大小,我似乎只是在屏幕上得到一个单元格。
这是我的代码:
class FlashViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
@IBOutlet var collectionView: UICollectionView!
var decks = [5]
override func viewDidLoad() {
super.viewDidLoad()
// Move on ...
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 75, left: 20, bottom: 10, right: 20)
layout.itemSize = CGSize(width: 150, height: 200)
collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
self.collectionView.dataSource = self
self.collectionView.delegate = self
collectionView.registerClass(DeckCollectionViewCell.self, forCellWithReuseIdentifier: "DeckCollectionViewCell")
collectionView.backgroundColor = UIColor.whiteColor()
self.view.addSubview(collectionView!)
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.decks.count
}