画面遷移しようとするとシミュレーターが落ちる Thread 1: signal SIGABRT
swift初学者です。
チュートリアルを参考にSNSアプリを制作中です。
シミュレーターを立ち上げ、HomeViewControllerからProfileViewControllerへ画面遷移しようとするとエラーになります。
以下コンソールの内容です。
2020-10-16 20:48:57.727132+0900 gyosufan[3430:98262] [Firebase/Crashlytics] Version 4.3.1 2020-10-16 20:48:57.728478+0900 gyosufan[3430:98483] 6.28.0 - [Firebase/Analytics][I-ACS023007] Analytics v.60602000 started 2020-10-16 20:48:57.729060+0900 gyosufan[3430:98483] 6.28.0 - [Firebase/Analytics][I-ACS023008] To enable debug logging set the following application argument: -FIRAnalyticsDebugEnabled (see http://goo.gl/RfcP7r) 2020-10-16 20:48:57.797957+0900 gyosufan[3430:98493] 6.28.0 - [Firebase/Analytics][I-ACS031025] Analytics screen reporting is enabled. Call +[FIRAnalytics setScreenName:setScreenClass:] to set the screen name or override the default screen class name. To disable screen reporting, set the flag FirebaseScreenReportingEnabled to NO (boolean) in the Info.plist 2020-10-16 20:48:57.798706+0900 gyosufan[3430:98489] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed 2020-10-16 20:48:57.883844+0900 gyosufan[3430:98482] 6.28.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement 2020-10-16 20:48:57.892187+0900 gyosufan[3430:98490] 6.28.0 - [Firebase/Analytics][I-ACS800023] No pending snapshot to activate. SDK name: app_measurement 2020-10-16 20:48:58.281435+0900 gyosufan[3430:98490] 6.28.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled 2020-10-16 20:48:58.303866+0900 gyosufan[3430:98490] 6.28.0 - [Firebase/Crashlytics][I-CLS000000] Failed to download settings Error Domain=FIRCLSNetworkError Code=-5 "(null)" UserInfo={status_code=404, type=2, request_id=, content_type=text/html; charset=utf-8} Could not cast value of type 'gyosufan.ProfileTabsCollectionReusableView' (0x107cdf8e8) to 'gyosufan.ProfileInfoHeaderCollectionReusableView' (0x107cdfc80). 2020-10-16 20:49:00.337157+0900 gyosufan[3430:98262] Could not cast value of type 'gyosufan.ProfileTabsCollectionReusableView' (0x107cdf8e8) to 'gyosufan.ProfileInfoHeaderCollectionReusableView' (0x107cdfc80). Could not cast value of type 'gyosufan.ProfileTabsCollectionReusableView' (0x107cdf8e8) to 'gyosufan.ProfileInfoHeaderCollectionReusableView' (0x107cdfc80). CoreSimulator 732.17 - Device: iPhone SE (2nd generation) (52F44A5A-DA3B-4922-8049-5BE63803AA59) - Runtime: iOS 14.0 (18A372) - DeviceType: iPhone SE (2nd generation)
ProfileViewController
swift
1import UIKit 2 3//profile view controller 4final class ProfileViewController: UIViewController { 5 6 private var collectionView: UICollectionView? 7 8 override func viewDidLoad() { 9 super.viewDidLoad() 10 view.backgroundColor = .systemBackground 11 configureNavigationBar() 12 13 let layout = UICollectionViewFlowLayout() 14 layout.scrollDirection = .vertical 15 layout.minimumLineSpacing = 1 16 layout.minimumInteritemSpacing = 1 17 layout.sectionInset = UIEdgeInsets(top: 0, left: 1, bottom: 0, right: 1) 18 let size = (view.width - 4)/3 19 layout.itemSize = CGSize(width: size, height: size) 20 collectionView = UICollectionView(frame: .zero, 21 collectionViewLayout: layout) 22 collectionView?.backgroundColor = .red 23 24 //cell 25 collectionView?.register(PhotoCollectionViewCell.self, 26 forCellWithReuseIdentifier: PhotoCollectionViewCell.identifier) 27 28 //header 29 collectionView?.register(ProfileInfoHeaderCollectionReusableView.self, 30 forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: ProfileInfoHeaderCollectionReusableView.identifier) 31 collectionView?.register(ProfileTabsCollectionReusableView.self, 32 forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: ProfileTabsCollectionReusableView.identifier) 33 34 collectionView?.delegate = self 35 collectionView?.dataSource = self 36 guard let collectionView = collectionView else { 37 return 38 } 39 view.addSubview(collectionView) 40 } 41 42 override func viewDidLayoutSubviews() { 43 super.viewDidLayoutSubviews() 44 collectionView?.frame = view.bounds 45 } 46 47 private func configureNavigationBar() { 48 navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "gear"), 49 style: .done, 50 target: self, 51 action: #selector(didTapSettingButton)) 52 } 53 54 @objc private func didTapSettingButton() { 55 let vc = SettingViewController() 56 vc.title = "設定" 57 navigationController?.pushViewController(vc, animated: true) 58 } 59} 60 61extension ProfileViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { 62 func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 63 return 30 64 } 65 66 func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 67 let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoCollectionViewCell.identifier, for: indexPath) as! PhotoCollectionViewCell 68 69 cell.configure(debug: "test") 70 return cell 71 } 72 73 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 74 collectionView.deselectItem(at: indexPath, animated: true) 75 } 76 77 func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { 78 79 guard kind == UICollectionView.elementKindSectionHeader else { 80 //footer 81 return UICollectionReusableView() 82 } 83 let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, 84 withReuseIdentifier: ProfileInfoHeaderCollectionReusableView.identifier, 85 for: indexPath) as! ProfileInfoHeaderCollectionReusableView 86 return header 87 } 88 89 func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { 90 if section == 0 { 91 return CGSize(width: collectionView.width, 92 height: collectionView.height/3) 93 } 94 95 return .zero 96 } 97} 98
試したこと
ググった結果、IBoutletが黄色くなっている箇所をつなぎ直す、など出てきましたが
それらしい箇所を見つけることもできず、、
助言いただければ幸いです。
xcode12.0.1です。
追記です。
Thread 1: signal SIGABRT
のメッセージは
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: ProfileInfoHeaderCollectionReusableView.identifier, for: indexPath) as! ProfileInfoHeaderCollectionReusableView
の as 部分に出ています。
それぞれの型は見直しても違いを確認できていません。。
さらに追記です。
エラーに関係すると思われる箇所です。
import UIKit class ProfileInfoHeaderCollectionReusableView: UICollectionReusableView { static let identifier = "ProfileInfoHeaderCollectionReusableView" override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .systemBlue clipsToBounds = true } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }
import UIKit class ProfileTabsCollectionReusableView: UICollectionReusableView { static let identifier = "ProfileInfoHeaderCollectionReusableView" override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .orange } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/10/18 00:42
2020/10/18 04:17