集合视图单元格未显示

mai*_*idi 14 xcode collectionview ios uicollectionviewcell swift

我希望显示尽可能多的数组collectionViewCells,buttons因为我的数组中有字符串.但是当我启动模拟器时,只有背景CollectionView但没有显示细胞.可能是什么错误?

这是CollectionViewController我附加到CollectionViewmain.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
}
Run Code Online (Sandbox Code Playgroud)

}

这些是Collection View Controller的连接:

连接

故事板上的View Controller:

视图 - 控制

Pav*_*kal 13

你是否设置了CollectionViewController故事板身份检查员?:)

我会尝试reloadData()在更改viewDidLoad方法中的数据后调用.

希望有所帮助