【发布时间】:2018-12-22 12:12:11
【问题描述】:
我正在使用 XIB 制作自定义 collectionview 单元格。
collectionview 作为扩展放置在 viewController 中。
这是我用来调用 Xib 视图的代码,但我收到一条错误消息,告诉我需要使用重用标识符。但我不知道在使用 XIB 时如何使用它。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = Bundle.main.loadNibNamed("CustomCell", owner: self, options: nil)?.first as! CustomCell
return cell
}
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“从 -collectionView:cellForItemAtIndexPath: 返回的单元格没有重用标识符 - 必须通过调用 -dequeueReusableCellWithReuseIdentifier:forIndexPath: 来检索单元格” *** 首先抛出调用栈:
【问题讨论】:
标签: ios swift xib collectionview reuseidentifier