我使用纯粹的故事板界面构建器创建了一个Collection View。这就是故事板的样子:
我的收藏视图的属性也是默认属性。我还没有在我的ViewController.swift
中写任何东西。
出于某种原因,当我在手机/模拟器上运行时,没有任何按钮显示。
答案 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
,拖放即可看到图片:
注意: delegate
在您完成相关课程的上述手续时会出现。