puuurm / swift-weatherforecast

iOS app
1 stars 0 forks source link

UITableViewDelegate 역할 분담 #28

Closed puuurm closed 6 years ago

puuurm commented 6 years ago

테이블 뷰 API 중 데이터 mapping을 어디서 해야할 지에 대한 고민

  1. tableView(_:cellForRowAt:): Asks the data source for a cell to insert in a particular location of the table view. The returned UITableViewCell object is frequently one that the application reuses for performance reasons. You should fetch a previously created cell object that is marked for reuse by sending a dequeueReusableCell(withIdentifier:) message to tableView. Various attributes of a table cell are set automatically based on whether the cell is a separator and on information the data source provides, such as for accessory views and editing controls.

  2. tableView(_:willDisplay:forRowAt:) : Tells the delegate the table view is about to draw a cell for a particular row. A table view sends this message to its delegate just before it uses cell to draw a row, thereby permitting the delegate to customize the cell object before it is displayed. This method gives the delegate a chance to override state-based properties set earlier by the table view, such as selection and background color. After the delegate returns, the table view sets only the alpha and frame properties, and then only when animating rows as they slide in or out.

해결: https://stackoverflow.com/questions/42649231/uitableview-cellforrowat-vs-willdisplay 상태 관련 프로퍼티를 설정하는 경우가 아니라면 tableView(_:cellForRowAt:)에 구현한다.