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

[220727] TIL #71

Closed
Taehyeon-Kim opened this issue Jul 27, 2022 · 1 comment
Closed

[220727] TIL #71

Taehyeon-Kim opened this issue Jul 27, 2022 · 1 comment
Assignees

Comments

@Taehyeon-Kim
Copy link
Owner

Taehyeon-Kim commented Jul 27, 2022

뷰와 데이터 관련한 것은 분리하도록 하자.

역할을 분리해서 함수를 작성하자.

UIViewController + UITableView

UITableViewController만 사용할 수 있으면 얼마나 편할까? 그러나 UITableViewController를 사용하는 경우에는 좀 더 유연한 화면 구성이 어렵다. 이미 화면 전체가 테이블뷰로 가득 차 있어 영역의 크기 조정이 어렵기 때문이다. (이 말인 즉슨 RootView가 UITableView라는 것이다.) 그렇기에 TableView만 따로 올려서 화면을 구성하는 경우가 더 많다.

  1. TableView 생성 + 아웃렛 연결
  2. TableViewCell 생성 (프로토타입 셀, XIB 이용) + 셀 클래스 연결 + 아웃렛 연결
  3. TableView에 필요한 프로토콜 선언 + 필수 메서드 구현
  4. 뷰 객체와 프로토콜 연결(위임)

Property Observer

저장 프로퍼티에서 사용된다. 프로퍼티의 값이 변경될 때마다 호출된다.

  • willSet (newValue) : 값이 변경(저장)되기 직전에 호출
  • didSet (oldValue) : 값이 변경(저장)된 이후에 호출
var nickname: String {
    willSet(newNickname) {
        print("유저 닉네임이 \(nickname)에서 \(newNickname)로 변경될 예정이에요")
    }
    didSet {
        print("유저 닉네임 변경 완료!!!! \(oldValue) -> \(nickname)으로 바뀜!")
    }
}
static var totalOrderCount = 10 {
    willSet {
        print("총 주문 건수가 \(totalOrderCount)에서 \(newValue)로 변경될 예정입니다.")
    }
    didSet {
        print("총 주문 건수가 \(oldValue)에서 \(totalOrderCount)로 변경되었습니다.")
    }
}
@Taehyeon-Kim
Copy link
Owner Author

셀 재사용 이슈

  • 화면과 데이터는 따로 논다. (독립적이다.)

자료구조를 딕셔너리로 만들어서 문제를 해결하려고 했지만

  1. 순서가 없다.
  2. indexPath를 활용할 수 없다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant