【发布时间】:2015-01-20 03:20:50
【问题描述】:
我在 Storyboard 中的 UICollectionViewController 中有一个 UICollectionView。 UICollectionViewController 链接到我的自定义class MasterViewController: UICollectionViewController, UICollectionViewDataSource, UICollectionViewDelegate,它的委托和数据源在情节提要中链接到这个类。
我在故事板中有一个原型 UICollectionViewCell,标识符为“MyCell”,来自我的自定义 class Cell: UICollectionViewCell
在cellForItemAtIndexPath 方法中,应用程序在以下行崩溃:let cell:Cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyCell", forIndexPath: indexPath) as Cell
我不明白为什么。 registerClass:forCellWithReuseIdentifier:方法我没有实现,storyboard的标识符正好是“MyCell”,查了很多遍,delegate和datasource都链接到了正确的类。
当应用程序崩溃时,控制台中不会打印任何内容,只是“(lldb)”
这是我的代码:
class MasterViewController: UICollectionViewController,UICollectionViewDataSource,UICollectionViewDelegate {
var objects = [ObjectsEntry]()
@IBOutlet var flowLayout: UICollectionViewFlowLayout!
override func awakeFromNib() {
super.awakeFromNib()
}
override func viewDidLoad() {
super.viewDidLoad()
flowLayout.itemSize = CGSizeMake(collectionView!.bounds.width - 52, 151)
}
// MARK: - Collection View
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return objects.count
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell:Cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyCell", forIndexPath: indexPath) as Cell
return cell
}
【问题讨论】:
-
这里是设置基本集合视图和集合视图单元的演练:stackoverflow.com/questions/31735228/…
标签: ios swift storyboard uicollectionview uicollectionviewcell