質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

2回答

1717閲覧

画面遷移しようとするとシミュレーターが落ちる Thread 1: signal SIGABRT

uskitm

総合スコア0

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2020/10/16 12:17

編集2020/10/18 12:46

画面遷移しようとするとシミュレーターが落ちる 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") } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

Could not cast value of type 'gyosufan.ProfileTabsCollectionReusableView' (0x107cdf8e8) to 'gyosufan.ProfileInfoHeaderCollectionReusableView' (0x107cdfc80).

[直訳] 'gyosufan.ProfileTabsCollectionReusableView' 型の値を、'gyosufan.ProfileInfoHeaderCollectionReusableView'型にキャスト(型変換)することが出来ません!

というのがエラーメッセージなのですから、これらの型の値を使っているところ、それらの型変換をしているところ、のコードを確認してください。

投稿2020/10/16 12:52

coco_bauer

総合スコア6915

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

uskitm

2020/10/18 00:42

回答ありがとうございます。 それぞれの型の間違った点が見つけられないのですが 別のクラスも関与していると言うことなのでしょうか。。
coco_bauer

2020/10/18 04:17

collectionView.dequeueReusableSupplementaryView メソッドの定義が質問のコードにはみあたりません。このメソッドの返り値の型は、どのように定義されているのでしょうか? それが、gyosufan.ProfileTabsCollectionReusableViewだったら、質問のエラーメッセージが出ると思うのです。 お手数ですが、「それぞれの型は見直しても違いを確認できていません」を確認できるだけのプログラムコードを質問に追加してください。 エラーがas のところで出ているということは、元の値の型と、asで指定した型(それをキャストする型)が合っていないのでしょう。 「それぞれの型の間違った点が見つけられない」ということで、それぞれの型どうしのキャストでエラーが出ない事が保証できる訳ではないです。 そういう視点で、もう一度プログラムの全てのコードを見直すことをお勧めします。
guest

0

自己解決

こちら記述ミスでした。。

swift

1class ProfileTabsCollectionReusableView: UICollectionReusableView { 2 static let identifier = "ProfileInfoHeaderCollectionReusableView"

下記に修正することで改善されました。

swift

1class ProfileTabsCollectionReusableView: UICollectionReusableView { 2 static let identifier = "ProfileTabsCollectionReusableView"

投稿2020/10/19 07:06

uskitm

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問