Skip to content

Commit

Permalink
[Feat] Health-Food-Me#55 - 스크랩 버튼 이벤트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
0inn committed Jul 14, 2022
1 parent db64d83 commit 0842b9b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,34 @@ import UIKit

import SnapKit

protocol ScrapCVCDelegate: AnyObject {
func ScrapCVCButtonDidTap(index: Int, isSelected: Bool)
}

class ScrapCVC: UICollectionViewCell, UICollectionViewRegisterable {

// MARK: - Properties

static var isFromNib: Bool = false
var index: Int = 0
weak var delegate: ScrapCVCDelegate?

// MARK: - UI Components

private let storeImageView: UIImageView = {
private var storeImageView: UIImageView = {
let iv = UIImageView()
return iv
}()

private let scrapButton: UIButton = {
private lazy var scrapButton: UIButton = {
let btn = UIButton()
btn.setImage(ImageLiterals.Scrap.bookmarkInactiveIcon, for: .normal)
btn.setImage(ImageLiterals.Scrap.bookmarkIcon, for: .selected)
btn.addTarget(self, action: #selector(didTapScrapButton(_:)), for: .touchUpInside)
return btn
}()

private let storeNameLabel: UILabel = {
private var storeNameLabel: UILabel = {
let lb = UILabel()
lb.textColor = .black
lb.font = .NotoMedium(size: 14)
Expand Down Expand Up @@ -57,6 +65,15 @@ class ScrapCVC: UICollectionViewCell, UICollectionViewRegisterable {
}
}

// MARK: - @objc Methods

extension ScrapCVC {
@objc func didTapScrapButton(_ sender: UIButton) {
sender.isSelected.toggle()
delegate?.ScrapCVCButtonDidTap(index: index, isSelected: sender.isSelected)
}
}

// MARK: - Methods

extension ScrapCVC {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ struct ScrapDataModel: Codable {
extension ScrapDataModel {
static var sampleScrapData: [ScrapDataModel] = [
ScrapDataModel(scrapimageUrl: "tempBurger", storeName: "써브웨이 동대문역사문화공원역점", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "", storeName: "진짜 맛있는 건강 버거", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "", storeName: "써브웨이 동대문역사문화공원역점", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "", storeName: "진짜 맛있는 건강 버거", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "", storeName: "써브웨이 동대문역사문화공원역점", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "", storeName: "진짜 맛있는 건강 버거", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "", storeName: "써브웨이 동대문역사문화공원역점", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "", storeName: "진짜 맛있는 건강 버거", storeLocation: "서울시 용산구")
ScrapDataModel(scrapimageUrl: "tempBurger", storeName: "진짜 맛있는 건강 버거", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "tempBurger", storeName: "써브웨이 동대문역사문화공원역점", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "tempBurger", storeName: "진짜 맛있는 건강 버거", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "tempBurger", storeName: "써브웨이 동대문역사문화공원역점", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "tempBurger", storeName: "진짜 맛있는 건강 버거", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "tempBurger", storeName: "써브웨이 동대문역사문화공원역점", storeLocation: "서울시 용산구"),
ScrapDataModel(scrapimageUrl: "tempBurger", storeName: "진짜 맛있는 건강 버거", storeLocation: "서울시 용산구")
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ extension ScrapVC: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: ScrapCVC.className, for: indexPath) as? ScrapCVC else { return UICollectionViewCell() }
cell.setData(data: ScrapDataModel.sampleScrapData[indexPath.row])
cell.index = indexPath.row
cell.delegate = self
return cell
}
}
Expand All @@ -150,6 +152,12 @@ extension ScrapVC: UICollectionViewDelegateFlowLayout {
}
}

extension ScrapVC: ScrapCVCDelegate {
func ScrapCVCButtonDidTap(index: Int, isSelected: Bool) {
print("\(index) 번 스크랩 \(isSelected) 상태")
}
}

// MARK: - Network

extension ScrapVC {
Expand Down

0 comments on commit 0842b9b

Please sign in to comment.