[Swift] CollectionView Cell _ Lingo Feedback

2022. 11. 1. 17:36ใ†Programming/Swift

 

 

 

 

 

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SelectPlanetCollectionViewCell.identifier, for: indexPath) as? SelectPlanetCollectionViewCell else { return UICollectionViewCell() }
        
        let selectedPlanetName = planetList[indexPath.row].planetName
        let selectedPlanetImage = planetList[indexPath.row].planetImage
        
        cell.planetNameLabel.text = selectedPlanetName
        cell.planetImageView.image = selectedPlanetImage
        
        return cell
    }
    
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SelectPlanetCollectionViewCell.identifier, for: indexPath) as? SelectPlanetCollectionViewCell
        
        let selectedPlanet = planetList[indexPath.row]
        
        if (cell?.isSelected) != nil {
            contentsViewController.planet = selectedPlanet
            navigationController?.pushViewController(contentsViewController, animated: true)
        }
    }

 

 

 

1. Cell์˜ identifier 

: ์—ฌ๋Ÿฌ ๊ฐœ์˜ Cell ํŒŒ์ผ์ด ์žˆ์„ ์ˆ˜ ์žˆ๋‹ค. (๊ผญ ํ•˜๋‚˜์˜ Cell๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฒŒ ์•„๋‹ˆ๋‹ˆ๊นŒ)

-> identifier๋ฅผ ํ†ตํ•ด ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋„๋ก, ํ•จ์ˆ˜ ๋‚ด์—์„œ cell ์„ ์–ธ ์‹œ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ

-> cell์˜ ์žฌ์‚ฌ์šฉ : dequeueReusableCell

    : ์žฌ์‚ฌ์šฉํ•  ์ผ์ด ์—†๋‹ค๋ฉด, ๊ตณ์ด dequeueReusableCell ์•ˆ์จ๋„ ๋œ๋‹ค! ex) ๊ฐ„๋‹จํ•œ ์„ค์ • ๋ทฐ ๋“ฑ๋“ฑ

 

 

2. " ์Œ๋”ฐ์˜ดํ‘œ " ๋‚ด๋ถ€์— ๋“ค์–ด๊ฐ€๋Š” ๋ฌธ์ž์—ด ์ฃผ์˜

: ์˜คํƒ€๊ฐ€ ๋ฐœ์ƒํ•ด๋„, ์ปดํŒŒ์ผ๋Ÿฌ๊ฐ€ ์ธ์‹ํ•  ์ˆ˜ ์—†๋‹ค. (์ธ๊ฐ„ ์ฝ์œผ๋ผ๊ณ  ๋งŒ๋“  ๊ฒƒ)

-> ๋”ฐ๋ผ์„œ ํ•ด๋‹น ๋‚ด์šฉ๋“ค์€ ์—ฌ๋Ÿฌ๋ฒˆ ์‚ฌ์šฉ๋  ๊ฒฝ์šฐ, ๋”ฐ๋กœ ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•˜๊ณ  ์“ฐ๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

-> ์˜คํƒ€๊ฐ€ ๋‚˜๋”๋ผ๋„ OK -> ํ•ด๋‹น ๋ณ€์ˆ˜๋กœ ์—ฎ์ด๋ฉด ์ฝ”๋“œ๋Š” ์˜ค๋ฅ˜ ์—†์ด ๋Œ์•„๊ฐ€๋‹ˆ๊นŒ.

 

 

3. Planet์„ ๋„˜๊ธฐ๋ฉด ์ข‹์ง€ ์•Š์„๊นŒ?

-> ๊ธฐ์กด์—๋Š” setPlanet ํ•จ์ˆ˜๋ฅผ ํ†ตํ•ด, planet ์ด๋ฆ„๊ณผ ์ด๋ฏธ์ง€ ๊ฐ’์„ ๋„˜๊น€

-> ์ดํ›„ ํ–‰์„ฑ ๋ชจ๋ธ์— ๋‹ค๋ฅธ ๋ฐ์ดํ„ฐ๊ฐ€ ์ถ”๊ฐ€๋  ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ, Planet ์ž์ฒด๋ฅผ ๋„˜๊ธฐ๋Š” ๊ฒƒ์ด ์ข‹์ง€ ์•Š์„๊นŒ?

-> REFACTOR Commit์œผ๋กœ ์ˆ˜์ •ํ•ด์„œ ๋จธ์ง€ํ–ˆ๋‹ค :)