ContainerView で複数ビューを配置
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'
解決策
新規に作成したサブビュー用のViewControllerにクラスが割り当てられていなかった。
こちらに同様に作成していたViewController swiftファイルに記述したクラスを割り当てることで解決した。
2019/01/14 追記
また同様の"unrecognized selector sent to instance"の出たがまったく違う理由だった。
今回はコレクションビューを使用するViewControllerを作成していたのだが、クラスにUICollectionViewDataSource, UICollectionViewDelegate を継承するのを忘れていた。