Thread 1: signal SIGABRT(IBOutlet、IBActionの接続以外の問題で)
- 評価
- クリップ 0
- VIEW 669
Storyboard上で作業してないので、IBOutlet、IBActionの接続問題ではありません。
ただ、行った作業的にUI部品とコードの接続に問題があるんだと思います。
ユーザーページにheader sectionを作ろうと、デモのUI部品の設置を試みました。
元のユーザーページ
import UIKit
import Firebase
private let reuseIdentifier = "Cell"
class UserProfileVC: UICollectionViewController {
// MARK: - Properties
override func viewDidLoad() {
super.viewDidLoad()
// Register cell classes
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
// fetch user data
fetchCurrentUserData()
}
// MARK: - UICollectionView
override func numberOfSections(in collectionView: UICollectionView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 0
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return 0
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
return cell
}
// MARK: -API
func fetchCurrentUserData(){
guard let currentUid = Auth.auth().currentUser?.uid else { return }
Database.database().reference().child("users").child(currentUid).child("username").observeSingleEvent(of: .value) { (snapshot) in
guard let username = snapshot.value as? String else { return }
self.navigationItem.title = username
}
}
}
UI部品の為のファイルをユーザーページの同じ階層に追加し以下のコードを書きました。
import UIKit
class UserProfileHeader: UICollectionViewCell {
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .red
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
編集したユーザーページのコード
import UIKit
import Firebase
private let reuseIdentifier = "Cell"
#####追加
private let headerIdentifier = "UserProfileHeader"
######UICollectionViewDelegateFlowLayoutを追加
class UserProfileVC: UICollectionViewController, UICollectionViewDelegateFlowLayout {
// MARK: - Properties
override func viewDidLoad() {
super.viewDidLoad()
// Register cell classes
self.collectionView!.register(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
######追加
self.collectionView!.register(UserProfileHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier)
// background color
self.collectionView?.backgroundColor = .white
######追加ここまで
// fetch user data
fetchCurrentUserData()
}
// MARK: - UICollectionView
override func numberOfSections(in collectionView: UICollectionView) -> Int {
#######追加 return 0から return 1に変更
return 1
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of items
return 0
}
#######追加
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
return CGSize(width: view.frame.width, height: 200)
}
override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
// declare header
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath) as! UserProfileHeader
// return header
return header
}
######追加ここまで
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
return cell
}
// MARK: -API
func fetchCurrentUserData(){
guard let currentUid = Auth.auth().currentUser?.uid else { return }
Database.database().reference().child("users").child(currentUid).child("username").observeSingleEvent(of: .value) { (snapshot) in
guard let username = snapshot.value as? String else { return }
self.navigationItem.title = username
}
}
}
シミュレーターをビルドしたところユーザーページが開かず、
AppDelegate.swiftのclass AppDelegate周辺でThread 1: signal SIGABRTが表示されました。
xcodeのconsoleのエラーメッセージです。
reason: 'could not dequeue a view of kind: UICollectionElementKindSectionFooter with identifier UserProfileHeader - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
よろしくお願いします。
-
気になる質問をクリップする
クリップした質問は、後からいつでもマイページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
クリップを取り消します
-
良い質問の評価を上げる
以下のような質問は評価を上げましょう
- 質問内容が明確
- 自分も答えを知りたい
- 質問者以外のユーザにも役立つ
評価が高い質問は、TOPページの「注目」タブのフィードに表示されやすくなります。
質問の評価を上げたことを取り消します
-
評価を下げられる数の上限に達しました
評価を下げることができません
- 1日5回まで評価を下げられます
- 1日に1ユーザに対して2回まで評価を下げられます
質問の評価を下げる
teratailでは下記のような質問を「具体的に困っていることがない質問」、「サイトポリシーに違反する質問」と定義し、推奨していません。
- プログラミングに関係のない質問
- やってほしいことだけを記載した丸投げの質問
- 問題・課題が含まれていない質問
- 意図的に内容が抹消された質問
- 過去に投稿した質問と同じ内容の質問
- 広告と受け取られるような投稿
評価が下がると、TOPページの「アクティブ」「注目」タブのフィードに表示されにくくなります。
質問の評価を下げたことを取り消します
この機能は開放されていません
評価を下げる条件を満たしてません
質問の評価を下げる機能の利用条件
この機能を利用するためには、以下の事項を行う必要があります。
- 質問回答など一定の行動
-
メールアドレスの認証
メールアドレスの認証
-
質問評価に関するヘルプページの閲覧
質問評価に関するヘルプページの閲覧
check解決した方法
0
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
return CGSize(width: view.frame.width, height: 200)
}
referenceと書いて、上記のコードを出しましたが、僕の場合、referenceSizeForHeaderInSectionを選択しないといけませんでした。
投稿
-
回答の評価を上げる
以下のような回答は評価を上げましょう
- 正しい回答
- わかりやすい回答
- ためになる回答
評価が高い回答ほどページの上位に表示されます。
-
回答の評価を下げる
下記のような回答は推奨されていません。
- 間違っている回答
- 質問の回答になっていない投稿
- スパムや攻撃的な表現を用いた投稿
評価を下げる際はその理由を明確に伝え、適切な回答に修正してもらいましょう。
15分調べてもわからないことは、teratailで質問しよう!
- ただいまの回答率 88.36%
- 質問をまとめることで、思考を整理して素早く解決
- テンプレート機能で、簡単に質問をまとめられる
質問への追記・修正、ベストアンサー選択の依頼
fuzzball
2019/01/29 15:02 編集
Consoleにエラーメッセージが表示されていませんか?
amazon_106
2019/01/29 15:03
忘れてました。追加しておきます。
amazon_106
2019/01/29 15:28 編集
解決しました。
amazon_106
2019/01/29 15:30
https://teratail.com/questions/164025
こちらでfuzzballさんが答えていることを参考にコードを見直してみたら、
HederとすべきところをFooterとしていました。