きっかけ
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と同じ仕様を実現する場合は注意が必要ですね。