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

Feat/#10 #11

Merged
merged 6 commits into from
Nov 12, 2021
Merged

Feat/#10 #11

merged 6 commits into from
Nov 12, 2021

Conversation

heerucan
Copy link
Member

@heerucan heerucan commented Nov 1, 2021

📌 관련 이슈

closed #10

📌 변경 사항 및 이유

3차 과제를 이제서야 하였습니다.
박습니다. 김루희. daegari..

📌 PR Point

  1. 그동안 MVC 패턴을 제대로 쓰지 못하고 있는 것 같아서 좀 Controller의 비중을 줄여보려고 나름 View 와 관련된 부분은 최대한
    빼서 만들어봤는데 잘 되었는지 모르겠습니다.

  2. 도전과제는 ScrollViewStackView를 박아서 만들었습니다. **Dynamic Cell Size**를 사용하지 않았다는 점...;;..;;
    그렇게 한 이유 : TableView 안에 CollectionView .. 액자식 구성으로 만들고 싶지 않아서...

  3. 더미데이터가 꼴보기 싫어서 ModelClass로 만들어서 빼줬는데 클래스를 저렇게 사용하는 것이 맞나요?

  4. 코드의 발전.. mei you.. ;;

📌 참고 사항

  • HomeVChomeTV를 통째로 박아버렸습니다.

  • section 0 : indexPath.row 0 - channelTVC (TVC 안에 있는 CV가 있는 구조)

  • section 0 : indexPath.row 1 - tagTVC

  • section 1 : videoTVC

  • 상단 스크롤 애니메이션은 따로 구현하지 않았고 tableViewsection header를 사용했습니다.

  • code base... sorry...

📌구현화면

  • 우리 민혁이 봐주세요. 졸귀 아닙니까? 하하ㅏ핳...; ㅇㅉㅌㅂ..;
  • 오랜만에 UI를 짜며 느낀 점은 클론코딩을 해야겠다는 것 + UI 못 짜는 멍청이가 된 것 같아...;;;

여튼 궁금한 거 다 물어봐주세요. 지적대환영😊🐯

Copy link
Member

@jane1choi jane1choi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

선배 이번 과제도 열심히 하셨네..👍🏻
전체적으로 테이블 뷰에 다 넣어서 구현한 점이라던가 태그 셀 부분도
나랑 구현방식이 달라서 배울 점이 많은 것 같아!!
이번주도 수고했어요오🔥🔥🔥

}

/// Header
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거 switch문으로 케이스를 나눠주는 이유가 뭘까요..??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UIView를 하나 만들어서 고것을 테이블뷰의 헤더에 배치하는건가요,,?
요런 방법을 쓰면 상단 바를 재사용할 수 있나요??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아열! 코드를 보는 탁월한 사이다 마시고 취한 은주쵸이! 역싀

HomeTopView가 제가 따로 만들어둔 상단 네비바 부분인데
고놈 자식이 스크롤할 때 스윽 사라지잖아요?

이 부분이 뭔가 tableview section header 기능을 활용하면 구현할 수 있겠다 싶어서
viewForHeaderInSection 메소드에서
section 0번(channelTVC, tagTVC가 해당되는 부분)의 sectionHeader로 지정해줬어요.

그러면 이제 스크롤할 때 section 1번이 오게 되면 걔가 쇽샥하고 사라지니까유..


switch문 아니고 if 문으로 해도 됩니다~!
나눠준 이유는 section이 2개라고 해줬는데 HomeTopView를 section0에 주고, section1에는 안 줄 거라서...
그렇게 하기 위해서는 분기처리가 필수겟졀..?!

@@ -11,4 +11,13 @@ extension UIView {
public func addSubviews(_ view: [UIView]) {
view.forEach { self.addSubview($0) }
}

/// 각 TVC,CVC의 className을 String으로 가져올 수 있도록 연산 프로퍼티를 설정합니다. 이 값들은 나중에 Identifier에 잘 써먹을 수 있습니다 (by. 송지훈 - 28기 iOS 파트장님)
static var className: String {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NSStringFromClass 요거 어떻게 사용하는건지 설명해주실 수 있으까 선배...???

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 아이를 사용하면 예를 들어
ChannelTVC 클래스 파일을 만들어줬을 때
굳이 타입프로퍼티로 static let identifier = "ChannelTVC" 라고 선언하지 않고
클래스 자체에 ChannelTVC.className이라고 하면 요놈 자식이 문자열로 변환해줘서 identifier로 사용할 수 있어요.

혹 말로 이해가 안될까봐 아래 사용한 부분에 태그 걸어둘테니 확인해보셔라..

// MARK: - Properties

private let channelImageView = UIImageView().then {
$0.contentMode = .scaleAspectFit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 클로저도 어떻게 사용하는 건지 설명 한번만 해주세여 선배,,
나도 클로저 써보고 싶어열...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘는 Then 이라는 라이브러리입니다.
Swift Package Manager나 pod에 추가해서 사용해주면
기본적으로 저렇게 사용하는 건데 사진을 보면 좀 쉽게 이해할 거 같으어라~~

스크린샷 2021-11-05 오전 1 02 33

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

슨배들 다 Then 쓰시던데 저도 공부 함 해봐야 겠네여,,

default:
guard let cell = tableView.dequeueReusableCell(withIdentifier: VideoTVC.className) as? VideoTVC
else { return UITableViewCell() }
cell.setData(thumb: video.list[indexPath.row].makeImage(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요 setdata 부분은 xib로 구현하지 않아서 요렇게 세개를 넣어주는건가요??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엄... xib로 구현해도 setData가 필요하면 구현해야 할 겁니당..
세미나 때 RankTVC를 xib로 만들었지만 로고아이콘, 순위/제목/부제목 라벨 부분에 데이터 넣어주려고 setData 했던 것처럼요!


위에 ChannelTVC, TagTVC에 없는 이유는

- ChannelTVC의 경우,
: cell 파일 내부에 CollectionView를 만들고
거기에 또 CollectionViewCell을 등록해서 거기서 이미 setData를 했기 때문입니단

- TagTVC는
: 제가 꼼수부려서 따로 데이터를 넣어줄 필요가 없이.. 스택뷰에 태그 이미지 에셋들을 박아버렸기 때문이져..

var list: [Channel]

init() {
self.list = [Channel(name: "RUHEE", imageName: Const.Image.ggamju1),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요거요거 이미지들 따로 빼서 사용하는 방법 배워갑니다😊👍🏻


// MARK: - Properties

private lazy var tagScrollView = UIScrollView().then {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dynamic cell size 이용하지 않고 요렇게도 맨들 수 있구나!!!
stack view 활용 짱이네 선배.. 셀 개수가 많이 없다면 요런 방법도 좋을 것 같넹👍🏻

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼼수꼼수..
dynamic cell size 가 어려워설.. 꼼수 좀 부려봤어라~;;
dynamic cell size 를 공부해보도록 하겠다..

Comment on lines +10 to +19
protocol UITableViewRegisterable {
static func register(target: UITableView)
}

extension UITableViewRegisterable where Self: UITableViewCell {
static func register(target: UITableView) {
target.register(Self.self, forCellReuseIdentifier: Self.className)
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 UITableViewRegisterable 프로토콜을 TagTVC (테이블뷰 셀)클래스 파일에 채택해주면
프로토콜 내에 구현해 둔 register 함수를 쓸 수 있는데

얘를 사용하면 우리가 귀찮게
homeTV.register(TagTVC.self, forCellReuseIdentifier: TagTVC.identifier) 라고 안해줘도 되고
TagTVC.register(target: homeTV) 라고 써주면 됩니다.
좀 간편하져?

글구 요놈 자식을 사용해주려면 className extension이 필수로 있어야 합니다.

extension UITableViewRegisterable where Self: UITableViewCell {
      static func register(target: UITableView) {
          target.register(Self.self, forCellReuseIdentifier: Self.className)
      }
  }

왜냐면 저기에 써줬기 때문에...
그게 싫다면 아래처럼 써줌 될 거 같네유...

extension UITableViewRegisterable where Self: UITableViewCell {
      static func register(target: UITableView) {
          target.register(Self.self, forCellReuseIdentifier: Self.identifier)
      }
  }

그리고 아까 UIView + Extension에 있던 className 메소드를 사용하게 되면
homeTV.register(TagTVC.self, forCellReuseIdentifier: TagTVC.identifier) 인 것을
homeTV.register(TagTVC.self, forCellReuseIdentifier: TagTVC.className) 식으로 써줄 수 있어요

@jane1choi

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

근데 사실 이거 송지훈씨 코드에서 쇽샥 가져온 것임...ㅋ.....ㅋ.ㅋ.ㅋ. 아는 척..;;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

설명 맛집..👍🏻👍🏻 identifier 매번 쓰기 번거로웠는데 저도 요거 함 써봐야겠어열
쇽샥해서 정리해놓겠습니당 감사해요😊❤️

// MARK: - Properties

private let channelImageView = UIImageView().then {
$0.contentMode = .scaleAspectFit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘는 Then 이라는 라이브러리입니다.
Swift Package Manager나 pod에 추가해서 사용해주면
기본적으로 저렇게 사용하는 건데 사진을 보면 좀 쉽게 이해할 거 같으어라~~

스크린샷 2021-11-05 오전 1 02 33


// MARK: - Properties

private lazy var tagScrollView = UIScrollView().then {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

꼼수꼼수..
dynamic cell size 가 어려워설.. 꼼수 좀 부려봤어라~;;
dynamic cell size 를 공부해보도록 하겠다..

Comment on lines +25 to +27
ChannelTVC.register(target: $0)
TagTVC.register(target: $0)
VideoTVC.register(target: $0)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jane1choi 여기 이 부분!

}

/// Header
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞아열! 코드를 보는 탁월한 사이다 마시고 취한 은주쵸이! 역싀

HomeTopView가 제가 따로 만들어둔 상단 네비바 부분인데
고놈 자식이 스크롤할 때 스윽 사라지잖아요?

이 부분이 뭔가 tableview section header 기능을 활용하면 구현할 수 있겠다 싶어서
viewForHeaderInSection 메소드에서
section 0번(channelTVC, tagTVC가 해당되는 부분)의 sectionHeader로 지정해줬어요.

그러면 이제 스크롤할 때 section 1번이 오게 되면 걔가 쇽샥하고 사라지니까유..


switch문 아니고 if 문으로 해도 됩니다~!
나눠준 이유는 section이 2개라고 해줬는데 HomeTopView를 section0에 주고, section1에는 안 줄 거라서...
그렇게 하기 위해서는 분기처리가 필수겟졀..?!

default:
guard let cell = tableView.dequeueReusableCell(withIdentifier: VideoTVC.className) as? VideoTVC
else { return UITableViewCell() }
cell.setData(thumb: video.list[indexPath.row].makeImage(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엄... xib로 구현해도 setData가 필요하면 구현해야 할 겁니당..
세미나 때 RankTVC를 xib로 만들었지만 로고아이콘, 순위/제목/부제목 라벨 부분에 데이터 넣어주려고 setData 했던 것처럼요!


위에 ChannelTVC, TagTVC에 없는 이유는

- ChannelTVC의 경우,
: cell 파일 내부에 CollectionView를 만들고
거기에 또 CollectionViewCell을 등록해서 거기서 이미 setData를 했기 때문입니단

- TagTVC는
: 제가 꼼수부려서 따로 데이터를 넣어줄 필요가 없이.. 스택뷰에 태그 이미지 에셋들을 박아버렸기 때문이져..

Copy link
Member

@yangsubinn yangsubinn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

잘보고 갑니다...
코드 야무지게 쇽샥 해가겠습니다~ 감사합니다~!🍎🤍🦔

@@ -8,14 +8,18 @@
import UIKit

struct Const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

와오 이렇게 다 빼버리면 추가할 때도 여기 추가하고 뷰컨에서 적용만 해주면 되니까 편하겠네여....🙊

}

// MARK: - Custom Method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빈칸이야..?............... bin kan......? 일부러 냄겨두신거라면,,, 오케..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

금잔디 컨벤션.. 맞춘 ... 거.. 큼큼.. 휴우...

func setupAutoLayout() {
contentView.addSubviews([tagScrollView, lineView])
tagScrollView.addSubview(tagStackView)
tagStackView.addArrangedSubviews([Const.Tag.all, Const.Tag.today,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addArrangedSubviews는 처음 봤는데, stackView 코드로 짤 때 안에 subview를 순서대로 넣어주는 칭구인건가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yangsubinn 맞아유..! 원래는 addArrangedSubview인데 태현스 익스텐션 쇽샥 가져왔어라...

Copy link
Member

@i-colours-u i-colours-u left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI 잘 짜시면서 겸손하시네요 루희선배...
이제 기본적인 UI 구성요소나 함수 활용이나 구조 짜는 방법은 스스로 다 하실수 있을 것 같아서 크게 코멘트를 할 부분이 없을것 같구요!
(디테일한 코드 스타일이나 함수 따로 빼거나, 이런 사소한 것들은 몰라서 안한다의 영역보다는 - 나중에 팀 스타일 자체에서 맞추면 되는 부분이라고 생각해요!, 이 부분에 있어서는 어느순간 시점 이후로는 정답도 없는 영역이고 - 본인만의 스타일을 갖춰 나가는 단계라고 생각하거든요!!)

저도 항상 UI 및 뷰를 계속 반복해서 짜다보니까.. 혹은 매번 똑같은 방법으로 하다보니까 나중에 좀 기계적으로 하게 되는게 있어서 어느순간 매너리즘에 빠지게 되는 경우가 있더라구요? 저도 그럴때는 다른 사람들 구현 방식을 참고해보거나, 구성 자체를 달리해보거나, 평소에 사용하지 않았던 차원으로 접근하거나 등등 새로운 시도를 해보는게 조금 더 코드를 폭 넓게 이해할 수 있을 것 같아요!!!!

이번 과제도 고생하셧슴니다 🙇🏼

@heerucan heerucan closed this Nov 12, 2021
@heerucan heerucan reopened this Nov 12, 2021
@heerucan heerucan merged commit fdad5a2 into main Nov 12, 2021
@heerucan heerucan deleted the feat/#10 branch November 12, 2021 06:41
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.

[FEAT] iOS 3차 과제
4 participants