Skip to content

Commit

Permalink
✅[CHORE] #285 - 게시물 cell 클릭시 postId 넘겨서 구경하기도 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
hryeong66 committed Jul 26, 2022
1 parent b89b882 commit 7d9b97c
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ extension HomeAreaRecommandTVC: UICollectionViewDelegate, UICollectionViewDataSo

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
delegate?.isSelectedCVC(indexPath: indexPath)
postDelegate?.sendPostDriveElement(data: localList[indexPath.row])
guard let cell = collectionView.cellForItem(at: indexPath) as? CommonCVC else { return }
postDelegate?.sendPostDetail(with: cell.postID)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ extension HomeSeasonRecommandTVC: UICollectionViewDelegate, UICollectionViewData

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
delegate?.isSelectedCVC(indexPath: indexPath)
let cell = collectionView.cellForItem(at: indexPath) as? CommonCVC
let postid = cell!.postID
let sengingData = findDriveElementFrom(postId: postid)
postDelegate?.sendPostDriveElement(data: sengingData)
guard let cell = collectionView.cellForItem(at: indexPath) as? CommonCVC else { return }
postDelegate?.sendPostDetail(with: cell.postID)
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,8 @@ extension HomeSquareTVC: UICollectionViewDelegate, UICollectionViewDataSource, U

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
delegate?.isSelectedCVC(indexPath: indexPath)
let cell = collectionView.cellForItem(at: indexPath) as? CommonCVC
let postId = cell!.postID
let sendingData = findDriveElementFrom(postId: postId)
postDelegate?.sendPostDriveElement(data: sendingData)
guard let cell = collectionView.cellForItem(at: indexPath) as? CommonCVC else { return }
postDelegate?.sendPostDetail(with: cell.postID)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ extension HomeTodayDriveTVC: UICollectionViewDelegate ,UICollectionViewDataSourc
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
postDelegate?.sendPostDriveElement(data: todayDriveList[indexPath.row])
guard let cell = collectionView.cellForItem(at: indexPath) as? CommonCVC else { return }
postDelegate?.sendPostDetail(with: cell.postID)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ protocol ThemeCollectionViewCellDelegate: class {
}

protocol PostIdDelegate {
func sendPostDriveElement(data: DriveElement?)
func sendPostDetail(with postId: Int)
}

class ThemePostAllTVC: UITableViewCell {
Expand Down Expand Up @@ -114,10 +114,8 @@ extension ThemePostAllTVC: UICollectionViewDelegate, UICollectionViewDataSource,
}

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let cell = collectionView.cellForItem(at: indexPath) as? CommonCVC
let postId = cell!.postID
let sendingData = findDriveElementFrom(postId: postId)
postDelegate?.sendPostDriveElement(data: sendingData)
guard let cell = collectionView.cellForItem(at: indexPath) as? CommonCVC else { return }
postDelegate?.sendPostDetail(with: cell.postID)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
Expand Down
14 changes: 5 additions & 9 deletions ChaRo-iOS/ChaRo-iOS/Source/Views/VCs/HomeScene/HomePostVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,10 @@ extension HomePostVC: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CommonCVC", for: indexPath) as? CommonCVC else { return UICollectionViewCell() }

cell.clickedPostCell = { postid in
let nextVC = PostDetailVC()
nextVC.setPostId(id: postid)
self.navigationController?.pushViewController(nextVC, animated: true)
cell.clickedPostCell = { [weak self] postId in
let nextVC = PostDetailVC(postId: postId)
self?.navigationController?.pushViewController(nextVC, animated: true)
}


cell.titleLabel.font = UIFont.notoSansBoldFont(ofSize: 14)

guard let topCell = collectionView.dequeueReusableCell(withReuseIdentifier: "HomePostDetailCVC", for: indexPath) as? HomePostDetailCVC else {return UICollectionViewCell()}
Expand Down Expand Up @@ -330,9 +327,8 @@ func dismissDropDownWhenTappedAround() {

//postID 넘기기 위한 Delegate 구현
extension HomePostVC: PostIdDelegate {
func sendPostDriveElement(data: DriveElement?) {
let nextVC = PostDetailVC()
nextVC.setAdditionalDataOfPost(data: data)
func sendPostDetail(with postId: Int) {
let nextVC = PostDetailVC(postId: postId)
navigationController?.pushViewController(nextVC, animated: true)
}

Expand Down
8 changes: 3 additions & 5 deletions ChaRo-iOS/ChaRo-iOS/Source/Views/VCs/HomeScene/HomeVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,7 @@ class HomeVC: UIViewController {
default: print("잘못된 경우")
}
if let nextVC = nextVC {
nextVC.modalPresentationStyle = .fullScreen
self.present(nextVC, animated: true)
navigationController?.pushViewController(nextVC, animated: true)
}
}

Expand Down Expand Up @@ -605,9 +604,8 @@ extension HomeVC: CollectionViewCellDelegate {

//postID 넘기기 위한 Delegate 구현
extension HomeVC: PostIdDelegate {
func sendPostDriveElement(data: DriveElement?) {
let nextVC = PostDetailVC()
nextVC.setAdditionalDataOfPost(data: data)
func sendPostDetail(with postId: Int) {
let nextVC = PostDetailVC(postId: postId)
navigationController?.pushViewController(nextVC, animated: true)
}
}
Expand Down
36 changes: 14 additions & 22 deletions ChaRo-iOS/ChaRo-iOS/Source/Views/VCs/MyPageScene/MyPageVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -737,32 +737,24 @@ extension MyPageVC: UICollectionViewDelegate {
extension MyPageVC: UICollectionViewDataSource {

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let detailVC = PostDetailVC()
var postId = 0
var driveData = MyPageDrive()
//내가 작성한 글 태그 = 1 / 저장한 글 컬렉션 뷰 태그 = 2
if indexPath.row > 0 {
if collectionView.tag == 1 {
detailVC.setPostId(id: writenPostDriveData[indexPath.row-1].postID)
driveData = writenPostDriveData[indexPath.row-1]
} else {
detailVC.setPostId(id: savePostDriveData[indexPath.row-1].postID)
if collectionView.tag == 1 {
postId = writenPostDriveData[indexPath.row-1].postID
driveData = writenPostDriveData[indexPath.row-1]
} else {
postId = savePostDriveData[indexPath.row-1].postID
driveData = savePostDriveData[indexPath.row-1]
}
detailVC.setAdditionalDataOfPost(data: DriveElement(
postID: driveData.postID,
title: driveData.title,
image: driveData.image,
region: driveData.region,
theme: driveData.theme,
warning: driveData.warning,
year: driveData.year,
month: driveData.month,
day: driveData.day,
isFavorite: driveData.isFavorite))
}
if indexPath.row > 0 {
self.tabBarController?.tabBar.isHidden = true
self.navigationController?.pushViewController(detailVC, animated: true)
}

let detailVC = PostDetailVC(postId: postId)

if indexPath.row > 0 {
self.tabBarController?.tabBar.isHidden = true
self.navigationController?.pushViewController(detailVC, animated: true)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,49 +534,34 @@ extension OtherMyPageVC: UICollectionViewDataSource {
let detailCell = collectionView.dequeueReusableCell(withReuseIdentifier:HomePostDetailCVC.identifier , for: indexPath) as! HomePostDetailCVC
detailCell.delegate = self
detailCell.setSelectName(name: currentState)

if(indexPath.row == 0){
return detailCell
} else {
let writenElement = writenPostDriveData[indexPath.row-1]
var writenTags = [writenElement.region, writenElement.theme,
writenElement.warning ?? ""] as [String]
cell.setData(image: writenPostDriveData[indexPath.row-1].image,
title: writenPostDriveData[indexPath.row-1].title,
tagCount:writenTags.count, tagArr: writenTags,
heart:writenPostDriveData[indexPath.row-1].favoriteNum,
save: writenPostDriveData[indexPath.row-1].saveNum,
year: writenPostDriveData[indexPath.row-1].year,
month: writenPostDriveData[indexPath.row-1].month,
day: writenPostDriveData[indexPath.row-1].day,
postID: writenPostDriveData[indexPath.row-1].postID)
return cell

writenElement.warning ?? ""] as [String]
cell.setData(image: writenPostDriveData[indexPath.row-1].image,
title: writenPostDriveData[indexPath.row-1].title,
tagCount:writenTags.count, tagArr: writenTags,
heart:writenPostDriveData[indexPath.row-1].favoriteNum,
save: writenPostDriveData[indexPath.row-1].saveNum,
year: writenPostDriveData[indexPath.row-1].year,
month: writenPostDriveData[indexPath.row-1].month,
day: writenPostDriveData[indexPath.row-1].day,
postID: writenPostDriveData[indexPath.row-1].postID)
return cell
}
}


func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let detailVC = PostDetailVC()
if indexPath.row > 0{
//detailVC.setPostId(id: writenPostDriveData[indexPath.row-1].postID)
detailVC.setAdditionalDataOfPost(data: DriveElement.init(
postID: writenPostDriveData[indexPath.row-1].postID,
title: writenPostDriveData[indexPath.row-1].title,
image: writenPostDriveData[indexPath.row-1].image,
region: writenPostDriveData[indexPath.row-1].region,
theme: writenPostDriveData[indexPath.row-1].theme,
warning: writenPostDriveData[indexPath.row-1].warning,
year: writenPostDriveData[indexPath.row-1].year,
month: writenPostDriveData[indexPath.row-1].month,
day: writenPostDriveData[indexPath.row-1].day,
isFavorite: writenPostDriveData[indexPath.row-1].isFavorite))
if indexPath.row > 0 {
let postId = writenPostDriveData[indexPath.row-1].postID
let detailVC = PostDetailVC(postId: postId)
self.navigationController?.pushViewController(detailVC, animated: true)
}
}



}
extension OtherMyPageVC: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout:
Expand Down
4 changes: 2 additions & 2 deletions ChaRo-iOS/ChaRo-iOS/Source/Views/VCs/NotificationVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ extension NotificationVC {
otherVC.setOtherUserID(userID: notificationList[indexPath.row].followed ?? "")
self.navigationController?.pushViewController(otherVC, animated: true)
} else {
let detailVC = PostDetailVC()
detailVC.setPostId(id: notificationList[indexPath.row].postID ?? -1)
let postId = notificationList[indexPath.row].postID ?? -1
let detailVC = PostDetailVC(postId: postId)
self.navigationController?.pushViewController(detailVC, animated: true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,9 @@ extension SearchResultVC: UICollectionViewDataSource {
let dropDownCell = collectionView.dequeueReusableCell(withReuseIdentifier: HomePostDetailCVC.identifier, for: indexPath) as? HomePostDetailCVC
dropDownCell?.delegate = self
topCVCCell?.delegate = self
cell?.clickedPostCell = { postid in
let nextVC = PostDetailVC()
nextVC.setPostId(id: postid)
self.navigationController?.pushViewController(nextVC, animated: true)
cell?.clickedPostCell = { [weak self] postId in
let nextVC = PostDetailVC(postId: postId)
self?.navigationController?.pushViewController(nextVC, animated: true)
}
if indexPath.row == 0 {
if myCellIsFirstLoaded {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,8 @@ extension ThemePostVC: ThemeNetworkDelegate {
}

extension ThemePostVC: PostIdDelegate {
func sendPostDriveElement(data: DriveElement?) {
let nextVC = PostDetailVC()
nextVC.setAdditionalDataOfPost(data: data)
func sendPostDetail(with postId: Int) {
let nextVC = PostDetailVC(postId: postId)
navigationController?.pushViewController(nextVC, animated: true)
}
}
Expand Down

0 comments on commit 7d9b97c

Please sign in to comment.