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

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

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

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

Q&A

1回答

312閲覧

コレクションビューで使用するセルのregister(UserPostCell.self,)メソッドで登録でエラーになる

amazon_106

総合スコア50

Swift

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

0グッド

0クリップ

投稿2019/01/28 08:38

編集2022/01/12 10:55

初学者です。

何が原因でエラーになったか検討もつかないので、ページ全て貼り付けています。
追加のご指摘あれば、お答えします。
よろしくお願いします。

import UIKit import Firebase private let reuseIdentifier = "Cell" private let headerIdentifier = "UserProfileHeader" class UserProfileVC: UICollectionViewController, UICollectionViewDelegateFlowLayout { // MARK: - Properties override func viewDidLoad() { super.viewDidLoad() // register cell classes ##############エラー############## Use of unresolved identifier 'UserPostCell' self.collectionView!.register(UserPostCell.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 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) // Configure the cell 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 } } }

イメージ説明

イメージ説明

UserPostCellを定義

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! UserPostCell // Configure the cell return cell }

エラーコード
Use of undeclared type 'UserPostCell'
イメージ説明

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

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

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

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

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

guest

回答1

0

UserPostCellという名前のクラスが定義されていません。
スペルミスなどないか確認しましょう。

投稿2019/01/28 08:41

MasakiHori

総合スコア3384

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

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

amazon_106

2019/01/28 11:22

UserPostCellを定義してみたのですが、これはこれでエラーになるので今回は敢えて削除して回答を募りました。 編集でそのエラーも入れておきます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

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

ただいまの回答率
85.50%

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

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

質問する

関連した質問