Я хочу показать как можно больше collectionViewCells
с buttons
, поскольку в моем массиве есть строки. но когда я запускаю симулятор, есть только фон CollectionView
, но не показаны клетки. Что может быть ошибкой?
Вот код из моего CollectionViewController
, который я прикреплял к CollectionView
в main.storyboard:
class CollectionViewController: UICollectionViewController {
var Array = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
Array = ["1","2","3","4","5"]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func collectionView(collectionView: UICollectionView, numberOfItemsSection section: Int) -> Int {
return Array.count
}
override func
collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
var cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! UICollectionViewCell
var button = cell.viewWithTag(1) as! UIButton
button.titleLabel?.text = Array[indexPath.row]
return cell
}
}
Это соединения контроллера коллекции:
Контроллер просмотра на раскадровке: