0
0

More than 1 year has passed since last update.

collectionViewのFallbackでクラッシュ

Posted at

きっかけ

tableViewで

tableViewController.swift
if hoge {
  return UITableViewCell()
}

このようにFallbackしていて、同様にcollectionViewにも

collectionViewController.swift
if hoge {
  return UICollectionViewCell()
}

としていたらクラッシュしてしまった。

【クラッシュログ】

 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:'

原因

collectionViewの場合はregisterしたcell以外を返すとクラッシュするみたいです。。。
tableViewと同じ仕様を実現する場合は注意が必要ですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0