集合视图单元格未出现在集合视图中?

时间:2016-10-07 12:07:33

标签: ios swift uicollectionview uicollectionviewcell

我使用纯粹的故事板界面构建器创建了一个Collection View。这就是故事板的样子:

Storyboard

我的收藏视图的属性也是默认属性。我还没有在我的ViewController.swift中写任何东西。

Collection View

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

2 个答案:

答案 0 :(得分:3)

UICollectionView不支持UITableView等静态单元格。您必须在代码中设置其dataSource,委托和配置单元格。

答案 1 :(得分:2)

只需正确配置def __init__(self, verbose_name=None, name=None, auto_now=False, auto_now_add=False, **kwargs): kwargs['null'] = True kwargs['blank'] = True super( ZeroDateTimeField, self ).__init__(verbose_name, name, auto_now, auto_now_add, **kwargs) ,请参阅下面的代码和图片:

实施collectionView的{​​{1}}方法:

delegate

然后从collectionView设置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,拖放即可看到图片:

enter image description here

注意: delegate在您完成相关课程的上述手续时会出现。