unrecognized selector sent to instance
swift でのトラブルシューティング。
状況
ストーリーボードの中にContainerViewを配置し、自動生成されるViewController.swiftとは別のサブビュー用のViewControllerを作った。
ビルドは成功したものの、画面表示した途端に以下のエラー
[UIViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fa93240ed80
'NSInvalidArgumentException', reason: '-[UIViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x7fa93240ed80'
https://gyazo.com/0713542f2d8ab03688706ff2a15e2861
解決策
新規に作成したサブビュー用のViewControllerにクラスが割り当てられていなかった。
こちらに同様に作成していたViewController swiftファイルに記述したクラスを割り当てることで解決した。
https://gyazo.com/b24c555a9172071b73b46547f073fffc
2019/01/14 追記
また同様の"unrecognized selector sent to instance"の出たがまったく違う理由だった。
今回はコレクションビューを使用するViewControllerを作成していたのだが、クラスにUICollectionViewDataSource, UICollectionViewDelegate を継承するのを忘れていた。
https://gyazo.com/cf6d04ba2b8eceb886364f267f93fd31