Potato
์•ˆ๋…•ํ•˜์„ธ์š”, ๊ฐ์žก๋‹ˆ๋‹ค?๐Ÿฅ” ^___^ ๐Ÿ˜บ github ๋ฐ”๋กœ๊ฐ€๊ธฐ ๐Ÿ‘‰๐Ÿป

potato's iOS Story/๊ฐœ๋ฐœํ•˜๋ฉด์„œ ๋งŒ๋‚œ ์นœ๊ตฌ๋“ค

[UIKit] cell์ด ๋“ฑ๋ก๋˜์ง€ ์•Š์•˜๋‹ค๊ณ  ํ•˜๋ฉด์„œ ์˜ค๋ฅ˜๊ฐ€๋‚˜์„œ ๊ฐ‘์ž๊ธฐ ์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ๊ฐ€ ๊บผ์ง€๋Š”๋Ž์‡ผ?

๊ฐ์ž ๐Ÿฅ” 2022. 11. 7. 04:20
๋ฐ˜์‘ํ˜•

์ด๋Ÿฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด์„œ simulator๊ฐ€ ํ™–! ๊บผ์ง€๋Š” ์‚ฌํƒœ๊ฐ€๋ฐœ์ƒํ–ˆ๋‹ค.

์ด๋ ‡๊ฒŒ collecionView์™€ CollectionViewCell์€ ์ž˜ ๋œจ์ง€๋งŒ, ์Šคํฌ๋กค ๋‚ด๋ ค๊ฐ€๋‹ค๊ฐ€ ์•„๋ž˜๋ถ€๋ถ„์—์„œ ํ›… ๊บผ์ง€๋Š” ์‚ฌํƒœ๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ ์š”? ์—๋Ÿฌ๋ฅผ ์ž˜ ์ฝ์–ด๋ด…์‹œ๋‹ค.

โš ๏ธ Thread 1: "could not dequeue a view of kind: UICollectionElementKindCell with identifier AchieveSummaryLottieCollectionViewCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard”

์ง€๊ธˆ ๋‚ด๊ฐ€ cell๋กœ ๋„์›Œ์•ผํ•˜๋Š” ํ˜•ํƒœ๊ฐ€ ๋‘๊ฐ€์ง€์ด๋‹ค. ๊ทธ๋ž˜์„œ ๋‘๊ฐœ์˜ cell์„ ๋งŒ๋“ค์–ด์ค€๋‹ค์Œ, ์•„๋ž˜์ฒ˜๋Ÿผ ๋ถ„๊ธฐ์ฒ˜๋ฆฌ๋ฅผ ํ•ด๋†“์€ ์ƒํƒœ์ด๋‹ค.

// MARK: - UICollectionViewDataSource
extension MyNewsDrawerViewController: UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return self.myNewsData.count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        if myNewsData[indexPath.row].title == nil {
            guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: AchieveSummaryLottieCollectionViewCell.className, for: indexPath) as? AchieveSummaryLottieCollectionViewCell else { return UICollectionViewCell() }
            return cell
        } else {
            guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MyNewsDrawerCollectionViewCell.className, for: indexPath) as? MyNewsDrawerCollectionViewCell else { return UICollectionViewCell() }
            cell.setData(myNewsData[indexPath.row])
            return cell
        }
    }
}

์—ฌ๊ธฐ์„œ “AchieveSummaryLottieCollectionViewCell” ์ด ์ œ๋Œ€๋กœ ๋ถˆ๋Ÿฌ์™€์ง€์ง€ ์•Š๋‚˜๋ณด๋‹ค. identifier๊ฐ€ AchieveSummaryLottieCollectionViewCell์— ๋Œ€ํ•œ .nibํŒŒ์ผ ๋˜๋Š” ํด๋ž˜์Šค๋ฅผ ๋“ฑ๋กํ•˜๊ฑฐ๋‚˜ ์Šคํ† ๋ฆฌ๋ณด๋“œ์—์„œ ํ”„๋กœํ† ํƒ€์ž… ์…€์„ ์—ฐ๊ฒฐํ•ด์•ผ ํ•œ๋‹ค๊ณ  ๋‚˜์™€์žˆ๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

 

๐Ÿ‘€ ์ฐพ์•˜๋‹ค ์›์ธ

ใ…‹ใ…‹ใ…‹ใ…‹์ƒ๊ฐ๋ณด๋‹ค ๋นจ๋ฆฌ ์•Œ์•„๋ƒˆ๋‹ค. ์•„๋‹ˆ ์•„๋ฌด๋ฆฌ๋ด๋„ Cell์— ์ฝ”๋“œ๋Š” ์™„๋ฒฝํ•˜๊ณ , ๋ถ„๊ธฐ์ฒ˜๋ฆฌ๋„ ์—๋Ÿฌ๊ฐ€ ๋‚˜์ง€ ์•Š๊ฒŒ ์ž˜ ๋˜์–ด์žˆ๋Š”๋ฐ ์™œ ๋„์›Œ์ง€์ง€์•Š๋Š”๊ฑธ๊นŒ, ๊ณ ๋ฏผํ–ˆ๋Š”๋ฐ ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์•ˆ์จ์คฌ๋‹ค. ใ…‹ใ…‹

collectionView.register(AchieveSummaryLottieCollectionViewCell.self, forCellWithReuseIdentifier: AchieveSummaryLottieCollectionViewCell.className)

๊ทธ๋‹ˆ๊นŒ Collectionview์— ๋“ฑ๋ก์ด ๋˜์ง€ ์•Š์•˜๋‹ค๊ณ  ํ•ด๋‹น cell์ด ๋กœ๋“œ๋ ๋•Œ ์—๋Ÿฌ๊ฐ€ ๋‚˜๋ฉด์„œ simulator๊ฐ€ ๋ฉˆ์ถ˜๊ฒƒ์ด์—‡๋”ฐ~~

๋“ฑ๋ก์„ ๊ผญ ํ•ด์ฃผ์ž ~~! ^____^ (๋ฏผ๋งํ•œ ์—๋Ÿฌ) ์งœ์ž” ๋œ๋‹ค ๋งˆ์ง€๋ง‰์— ๋กœํ‹ฐ ๋“ค์–ด๊ฐ„๋‹ค ~ ๋ฃฐ๋ฃจ ๐ŸŽถ

 

๊ฒฐ๋ก  - ๊นŒ๋จน์ง€๋ง์ž register!!!

collectionView.register(AchieveSummaryLottieCollectionViewCell.self, forCellWithReuseIdentifier: AchieveSummaryLottieCollectionViewCell.className)
๋ฐ˜์‘ํ˜•