如何实例化一个collectionview 的cell?

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

上面是重用cell的写法, 但是如何每次都实例化一个collectionview的cell?

我尝试过 let cell = VideoViewCell()
直接报
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'the cell returned from -collectionView:cellForItemAtIndexPath: does not have a reuseIdentifier - cells must be retrieved by calling -dequeueReusableCellWithReuseIdentifier:forIndexPath:

google了也没找到合适的答案

阅读 5.1k
2 个回答

也试过 let cell = collectionView.cellForItemAtIndexPath(indexPath) as VideoViewCell 办法,直接报 fatal error: unexpectedly found nil while unwrapping an Optional value

是否没有注册

    [_collectionView registerClass:[BigRoomVideoCell class]
    forCellWithReuseIdentifier:CELL_IDENTIFIER];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题