[swift] codeschool: lv4. Table Views
table view conterller는 table view를 support하는 특별한 뷰임.
view contrller -> main view -> (scroll view -> label, image views)
table view contrller -> table view -> (table cell, table cell ... )
table cell안에 다양한 sub view가 들어갈 수 있음.
우측 아래에서 table view Controller를 찾아 추가하고,
항상 그렇듯 is Initial view controller 추가,
폴더 우클릭 - 새로운 파일 - 코코터치 - subclass를 UITableViewController로 수정
class 이름은 ProcutsTableViewController
그리고 identity inspector 에서 custom class에서 class이름을
ProcutsTableViewController 라고 바꾸어 준다.
그리고 ProcutCell 클릭후 Attribute Inspector에서
table view cell-identifier에서 ProductCell로 이름을 바꾼다.
table cell은 실제로 보이는 부분만 렌더링. 계속 재사용
계속 재사용하기 때문에 다른 view controller와는 달리 table cell을 위한 content를 code안에서 연결해줘야 한다.
class ProductsTableViewController: UITableViewConterller {
override func tableView(_ tableView: UITableView, numberofRowsInSection section: Int) ->Int {
return 5
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ProductCell", for: indexPath)
return cell
}
}
//ProductCell은 스토리보드에서 추가했던거임..