集合视图单元格没有出现在集合视图中? [英] Collection View Cells not appearing in Collection View?

查看:25
本文介绍了集合视图单元格没有出现在集合视图中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我纯粹使用故事板界面构建器创建了一个集合视图.这是故事板的样子:

I created a Collection View using purely the storyboard interface builder. This is what the storyboard looks like:

我的集合视图的属性也是默认的.我还没有在 ViewController.swift 中写入任何东西.

My collection view's properties are default as well. I haven't written anything into my ViewController.swift yet.

出于某种原因,当我在手机/模拟器上运行时,没有任何按钮显示.

For some reason, when I run on my phone / emulator, none of the buttons are showing.

推荐答案

只需正确配置 collectionView 看下面的代码和图片:

Just configure the collectionView properly see below code and image:

实现collectionViewdelegate方法:

class yourClassController: UICollectionViewDataSource, UICollectionViewDelegate {

override func numberOfSectionsInCollectionView(collectionView: 
    UICollectionView!) -> Int {
    return 1
}

override func collectionView(collectionView: UICollectionView!, 
    numberOfItemsInSection section: Int) -> Int {
    return yourArray.count
}

override func collectionView(collectionView: UICollectionView!, 
cellForItemAtIndexPath indexPath: NSIndexPath!) -> 
     UICollectionViewCell! {

     let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as CollectionViewCell

     // Configure the cell
     cell.backgroundColor = UIColor.blackColor()
     cell.textLabel?.text = "\(indexPath.section):\(indexPath.row)"
     cell.imageView?.image = UIImage(named: "circle")



    return cell
}

然后从您的 storyboard 设置 delegatedatasource 拖放查看图像:

Then from your storyboard set the delegate and datasource by drag and drop see image:

注意: collectionView 出现在你用它的相关类完成上述形式时.

Note: collectionView appears when you do complete above formality with its relevant class.

这篇关于集合视图单元格没有出现在集合视图中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆