카테고리 없음

iOS프로그래밍실무 (04.03)

k0223 2025. 4. 3. 16:45

맛집 iOS 앱개발 table view

스위프트 상속과 프로토콜 채택

TableView의 DataSource : UITableViewDataSource프로토콜

https://developer.apple.com/documentation/uikit/uitableviewdatasource

 

UITableViewDataSource | Apple Developer Documentation

The methods that an object adopts to manage data and provide cells for a table view.

developer.apple.com

 

UITableViewDataSource프로토콜 : 선택적 메서드

https://developer.apple.com/documentation/uikit/uitableviewdatasource

 

UITableViewDataSource | Apple Developer Documentation

The methods that an object adopts to manage data and provide cells for a table view.

developer.apple.com

 

TableView의 Delegate: UITableViewDelegate프로토콜

https://developer.apple.com/documentation/uikit/uitableviewdelegate

 

UITableViewDelegate | Apple Developer Documentation

Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.

developer.apple.com

테이블뷰 관련 delegate, datasource 그림 그리기

https://developer.apple.com/documentation/uikit/uitableviewdelegate

 

UITableViewDelegate | Apple Developer Documentation

Methods for managing selections, configuring section headers and footers, deleting and reordering cells, and performing other actions in a table view.

developer.apple.com

https://developer.apple.com/documentation/uikit/uitableviewdatasource

 

UITableViewDataSource | Apple Developer Documentation

The methods that an object adopts to manage data and provide cells for a table view.

developer.apple.com

UIViewController vs UIViewTableController

 

Table View Controller

 기본적으로 생성되는 View Controller 대신에 Table View Controller를 사용하는 것이 편하지만,

Table View에 대한 이해를 위해 View Controller를 이용하여 일일이 만들었습니다.

 

Swift에서 ViewController 클래스가 UITableViewDataSource 프로토콜을 채택했지만,

해당 프로토콜이 요구하는 필수 메서드들을 구현하지 않아서 처음엔 오류가 생깁니다.

indexPath는 테이블 뷰에서 특정 셀의 위치를 나타내는 값으로, IndexPath라는 타입으로 제공됩니다.

이 값은 두 가지 정보를 가지고 있습니다.

  1. section (섹션):
    테이블 뷰는 데이터를 그룹으로 나눌 수 있는데, 이 그룹 하나하나가 섹션이에요. 예를 들어 연락처 앱에서 'A', 'B', 'C' 식으로 분류된 리스트가 있다면, 각각이 섹션입니다.
  2. row (로우):
    각 섹션 안에 포함된 각 셀의 위치를 나타냅니다. 예를 들어 'A' 섹션에 "Alice", "Aaron", "Abby"라는 셀이 있다면, 각각의 row는 0, 1, 2가 됩니다.

Cell 추가