Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐ŸคŸ๐Ÿป 3์ฃผ์ฐจ ์„ธ๋ฏธ๋‚˜ - 2 #11

Merged
merged 13 commits into from
Aug 1, 2023

Conversation

ena-isme
Copy link
Contributor

@ena-isme ena-isme commented Aug 1, 2023

3์ฃผ์ฐจ

3์ฃผ์ฐจ ์„ธ๋ฏธ๋‚˜ -2 ์—์„œ๋Š” ๊ฐ„๋‹จํ•œ ๊ฐค๋Ÿฌ๋ฆฌ ํด๋ก  ์ฝ”๋”ฉ์„ ํ†ตํ•˜์—ฌ CollectionTableView ์— ๋Œ€ํ•œ ๊ฐœ๋…์„ ๊ณต๋ถ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

์ฃผ์š”์ฝ”๋“œ


PhotoCollectionViewCell ํŒŒ์ผ ๋‚ด์—์„œ Closure ๋ฅผ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋Š” Optional Stored Property ๊ตฌํ˜„ํ•œ ๋’ค, heartButtonTap ํ•˜์˜€์„ ๋•Œ ํด๋กœ์ €๊ฐ€ ํ˜ธ์ถœ๋˜๊ณ , VC ์—์„œ๋Š” ํด๋กœ์ € ๊ตฌ๋ฌธ์ด ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ์˜ต์…”๋„์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ฐ”์ธ๋”ฉํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋” ์ข‹์Šต๋‹ˆ๋‹ค!


๋˜ํ•œ cellForItemAt ์„ ํ†ตํ•˜์—ฌ ์Šคํฌ๋กค์„ ๋งจ ์•„๋ž˜๊นŒ์ง€ ๋‚ด๋ ธ๋‹ค๊ฐ€ ๋‹ค์‹œ ์˜ฌ๋ผ์™€๋„ ํ•˜ํŠธtap ์—ฌ๋ถ€๊ฐ€ ๋‚จ์•„์žˆ๋„๋ก ์ˆ˜์ •ํ•˜์˜€์Šต๋‹ˆ๋‹ค.


//PhotoCollectionViewCell ํŒŒ์ผ ๋‚ด๋ถ€
var handler: (() -> (Void))?
...
@objc
    func heartButtonTapped() {
        handler?()
    }
//PhotoViewControllerl ํŒŒ์ผ ๋‚ด๋ถ€
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoCollectionViewCell.identifier, for: indexPath) as? PhotoCollectionViewCell else { return UICollectionViewCell() }
        
        cell.configureCell(dummyCase[indexPath.item])
        
        cell.handler = { [weak self] in
            guard let self else { return }
            self.dummyCase[indexPath.item].heartTapped.toggle()
        }
        
        return cell
    }

heartImage ๋ฅผ ๋”ฐ๋กœ asset์— ์ถ”๊ฐ€ํ•ด์ฃผ์ง€ ์•Š์•„๋„ ๋‚ด๋ถ€์—์„œ ๋ถˆ๋Ÿฌ์˜ฌ ์ˆ˜ ์žˆ๋Š”์ง€ ์ฒ˜์Œ ์•Œ์•˜์Šต๋‹ˆ๋‹ค!

func updateButton() {
        let image = isTapped ? "heart.fill" : "heart"
        button.setImage(UIImage(systemName: image), for: .normal)
    }

์‹ค์Šต๊ฒฐ๊ณผ


Simulator.Screen.Recording.-.iPhone.14.Pro.-.2023-08-01.at.17.32.07.mp4

#6

@ena-isme ena-isme changed the title 3์ฃผ์ฐจ ์„ธ๋ฏธ๋‚˜ -2 3์ฃผ์ฐจ ์„ธ๋ฏธ๋‚˜ - 2 Aug 1, 2023
@ena-isme ena-isme self-assigned this Aug 1, 2023
@ena-isme ena-isme added enhancement New feature or request ๐Ÿ’ซ Seminar and removed enhancement New feature or request labels Aug 1, 2023
@ena-isme ena-isme merged commit 74e1a0b into main Aug 1, 2023
@ena-isme ena-isme changed the title 3์ฃผ์ฐจ ์„ธ๋ฏธ๋‚˜ - 2 3๏ธโƒฃ 3์ฃผ์ฐจ ์„ธ๋ฏธ๋‚˜ - 2 Aug 2, 2023
@ena-isme ena-isme changed the title 3๏ธโƒฃ 3์ฃผ์ฐจ ์„ธ๋ฏธ๋‚˜ - 2 ๐ŸคŸ๐Ÿป 3์ฃผ์ฐจ ์„ธ๋ฏธ๋‚˜ - 2 Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant