diff --git a/Toonie/Feed/RecommendView/RecommendCollectionViewCell.swift b/Toonie/Feed/RecommendView/RecommendCollectionViewCell.swift index 9314556..5cc67af 100644 --- a/Toonie/Feed/RecommendView/RecommendCollectionViewCell.swift +++ b/Toonie/Feed/RecommendView/RecommendCollectionViewCell.swift @@ -11,24 +11,66 @@ import UIKit // '지금나는 final class RecommendCollectionViewCell: UICollectionViewCell { + // MARK: - Properties + var toonID: String = "" + var toonName: String = "" + var instaID: String = "" + var instaUrl: String = "" + var instaThumnailUrl: String = "" + var instafollowerCnt: String = "" + var instaLatestPostUrl: String = "" + // MARK: - IBOutlets @IBOutlet private weak var recentToonImageView: UIImageView! - @IBOutlet private weak var artistLabel: UILabel! + @IBOutlet private weak var toonNameTitle: UILabel! @IBOutlet private weak var bookMarkButton: UIButton! + @IBOutlet weak var curationTagList: UILabel! override func prepareForReuse() { super.prepareForReuse() recentToonImageView.image = nil - artistLabel.text = nil + toonNameTitle.text = nil bookMarkButton.isSelected = false } // MARK: - Functions /// 컬렉션뷰셀 데이터 설정 - func setRecommendCollectionViewCellProperties() { - recentToonImageView.image = UIImage(named: "sample2") - artistLabel.text = "임유끼" + func setRecommendCollectionViewCellProperties(curationInfoList: ToonInfoList?) { + prepareForReuse() + + if let info = curationInfoList { + DispatchQueue.main.async { + if let url = URL(string: info.instaThumnailUrl ?? "") { + do { + let data = try Data(contentsOf: url) + self.recentToonImageView.image = UIImage(data: data) + } catch let error { + print("Error : \(error.localizedDescription)") + } + } + } + if let nameString = info.toonName { + toonNameTitle.text = nameString + } + + var tagList = "" + if let toonTagList = info.toonTagList { + for index in 0.. - + - + @@ -20,8 +20,9 @@ - + + @@ -72,16 +73,16 @@ - + + - diff --git a/Toonie/Feed/RecommendView/RecommendTableViewCell.swift b/Toonie/Feed/RecommendView/RecommendTableViewCell.swift index 4e3f183..d4b92a7 100644 --- a/Toonie/Feed/RecommendView/RecommendTableViewCell.swift +++ b/Toonie/Feed/RecommendView/RecommendTableViewCell.swift @@ -11,6 +11,10 @@ import UIKit // '지금 나는' 테이블뷰 셀 - storyboard에서 collectionView 소스분리가 되지않아 xib로 분리. final class RecommendTableViewCell: UITableViewCell { + // MARK: - Properties + private var titleString: String? = "" + private var curationTagArray: [ToonInfoList]? + // MARK: - IBOutlet @IBOutlet private weak var recommentTitleLabel: UILabel! @@ -20,6 +24,7 @@ final class RecommendTableViewCell: UITableViewCell { override func awakeFromNib() { super.awakeFromNib() setRecommendCollectionView() + } override func setSelected(_ selected: Bool, animated: Bool) { @@ -29,16 +34,36 @@ final class RecommendTableViewCell: UITableViewCell { // MARK: - Function ///delegate세팅 및 xib(nib) 세팅 - func setRecommendCollectionView() { + private func setRecommendCollectionView() { recommendCollectionView.delegate = self recommendCollectionView.dataSource = self let nibName = UINib(nibName: "RecommendCollectionViewCell", bundle: nil) - recommendCollectionView.register(nibName, forCellWithReuseIdentifier: "RecommendCollectionViewCell") + recommendCollectionView.register(nibName, + forCellWithReuseIdentifier: "RecommendCollectionViewCell") } func setRecommentTitleLabel(titleString: String?) { - recommentTitleLabel.text = titleString + if let title = titleString { + recommentTitleLabel.text = "#\(title)" + } + self.titleString = titleString + setCurationTag() + } + + private func setCurationTag() { + if let string = titleString { + CurationTagService.shared.getCurationTagList(tagName: string) { (result) in + if let curationTagArray = result { + self.curationTagArray = curationTagArray + } + + self.recommendCollectionView.reloadData() + + } + + } + } } @@ -46,7 +71,7 @@ final class RecommendTableViewCell: UITableViewCell { extension RecommendTableViewCell: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 3 + return curationTagArray?.count ?? 0 } func collectionView(_ collectionView: UICollectionView, @@ -55,7 +80,7 @@ extension RecommendTableViewCell: UICollectionViewDataSource { for: indexPath) as? RecommendCollectionViewCell else { return UICollectionViewCell() } - cell.setRecommendCollectionViewCellProperties() + cell.setRecommendCollectionViewCellProperties(curationInfoList: curationTagArray?[indexPath.row]) return cell } @@ -63,7 +88,18 @@ extension RecommendTableViewCell: UICollectionViewDataSource { // MARK: - UICollectionViewDelegate extension RecommendTableViewCell: UICollectionViewDelegate { - func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { -// print("선택 \(indexPath.row)") + func collectionView(_ collectionView: UICollectionView, + didSelectItemAt indexPath: IndexPath) { + + let storyboard = UIStoryboard(name: "Detail", bundle: nil) + if let viewController = storyboard + .instantiateViewController(withIdentifier: "DetailToonView") + as? DetailToonViewController { + viewController.detailToonID = curationTagArray?[indexPath.row].toonID + CommonUtility.sharedInstance.mainNavigationViewController? + .pushViewController(viewController, + animated: true) + } + } } diff --git a/Toonie/Feed/RecommendView/RecommendTableViewCell.xib b/Toonie/Feed/RecommendView/RecommendTableViewCell.xib index 7f143b2..0b42a66 100644 --- a/Toonie/Feed/RecommendView/RecommendTableViewCell.xib +++ b/Toonie/Feed/RecommendView/RecommendTableViewCell.xib @@ -1,11 +1,11 @@ - + - + @@ -26,13 +26,7 @@ - - + @@ -67,6 +61,12 @@ + diff --git a/Toonie/Feed/View/Feed.storyboard b/Toonie/Feed/View/Feed.storyboard index ed04efa..6441ab5 100644 --- a/Toonie/Feed/View/Feed.storyboard +++ b/Toonie/Feed/View/Feed.storyboard @@ -424,18 +424,18 @@ - - + + - + - + - + @@ -515,26 +515,26 @@