#実現したいこと
CollectionViewを導入したい。
Swiftで、CollectionViewを導入したいと考えております。
https://hayashi-rin.net/post-1157/amp
のサイト様の記述を参考にしながら作成したのですが、
プレビューするとThread1エラーが出てしまいます。
今回のアプリの補足としましては、
・NavigationControllerを導入している。
・アプリを開いたページから遷移して、CollectionViewのページへ移動
→この際にエラーが出てしまう。
発生している問題・エラーメッセージ
Thread 1: signal SIGABRT アプリ立ち上げ時からのconsoleは下記です。 2019-01-24 17:53:24.410338+0900 test3[62641:16194225] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles 2019-01-24 17:53:24.412006+0900 test3[62641:16194225] [MC] Reading from public effective user settings. 2019-01-24 17:53:33.247386+0900 test3[62641:16194225] -[test3.SecondViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x104d1b9a0 2019-01-24 17:53:33.248254+0900 test3[62641:16194225] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[test3.SecondViewController collectionView:numberOfItemsInSection:]: unrecognized selector sent to instance 0x104d1b9a0' *** First throw call stack: (0x1cb5ebef8 0x1ca7b9a40 0x1cb503154 0x1f85665c0 0x1cb5f1810 0x1cb5f34bc 0x1f7e3dbb4 0x1f7e3fc18 0x1f7e498c4 0x1f7e4b82c 0x1f7e45680 0x1f7e3dea4 0x1f7e3e6e4 0x1f7e1256c 0x1f89dbf44 0x1cfbcda34 0x1cfbd29c4 0x1cfb319d4 0x1cfb602f4 0x1cfb6115c 0x1cb579b94 0x1cb574828 0x1cb574dc8 0x1cb5745b8 0x1cd7e8584 0x1f8538bc8 0x1025e5448 0x1cb034b94) libc++abi.dylib: terminating with uncaught exception of type NSException
該当のソースコード
Swift4
1import UIKit 2 3class CollectionViewCell: UICollectionViewCell { 4 5 @IBOutlet var title:UILabel! 6 @IBOutlet var contents:UILabel! 7 8 override init(frame: CGRect) { 9 super.init(frame:frame) 10 } 11 12 required init?(coder aDecoder: NSCoder) { 13 super.init(coder:aDecoder)! 14 } 15 16 func collectionView(collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 17 let cell:CollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath as IndexPath) as! CollectionViewCell 18 cell.title.text = "title(indexPath.row)" 19 cell.contents.text = "text(indexPath.row)" 20 return cell 21 } 22 23 func numberOfSectionsIncollectionView(collectionView: UICollectionView) -> Int { 24 return 1 25 } 26 27 func collectionView(collectionView:UICollectionView,numberOfItemsInSection section:Int) -> Int{ 28 return 20 29 } 30 31 32}
試したこと
・StoryBoardとプログラムの接続で注意マークなどは出ていない
・identifierも設定できている。(cell)
デリゲートの設定がうまくいっていないのか、はたまたプログラミングの記述がおかしいのか・・・
3時間ほどネットで調べて見たのですが、うまい解法が浮かびませんでした・・・
アドバイスいただけますと幸いです。
何卒よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー