我想显示尽可能多的collectionViewCells
with 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
}
}
这些是集合视图控制器的连接:
故事板上的视图控制器:
您是否设置了CollectionViewController
到故事板身份检查员? :)
我会尝试打电话给reloadData()
更改数据后viewDidLoad
method.
希望有帮助
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)