[RC]第3週コンセプト-UITAbleView


<質問1>なぜTable Viewを使うのですか?
<問題2>Table Viewのコンポーネント?
<問題3>Table Viewの実装方法

[使用理由]


1.データの可変性に対応するため。


逆に、データの数が固定されている場合は、ScollViewを使用します。


2.どのくらいのデータがあるかわからない場合


3.企画者の気まぐれに対応するため。


(ボタンが3つから4つに増えた)->なのでアプリを作成する際に、企画者に変更の可能性があるか聞いて、アプリを作成します。


Table Viewを作成した場合?


-> Dynamic StackView + ScrollView


アプリケーションの作成時に推奨される順序


まずモデルを作成し、UIを作成します.

[コンポーネント]


1.UI->ユニットの構成

func tableView(_ tableView: UITableView,
                   cellForRowAt indexPath: IndexPath) -> UITableViewCell {
}

2.セル数

func tableView(_ tableView: UITableView,
                   numberOfRowsInSection section: Int) -> Int {     
}

[UItableViewに関するメソッド]


UITableViewDelegate

  • ビュー付きインクリメンタルゲートウェイオブジェクトUITableViewDelegateプロトコル
  • を採用
  • delegateは、tableビューのビジュアル部分の変更、行選択の管理、添付ファイルビューのサポート、tableビューの個別行の編集を支援します.
  • モデル-ビュー-コントローラ(MVC)設計モードにおいて、コントローラに関連する
  • 必要な実施方法がない
  • .
    // 지정된 행이 선택되었음을 알리는 메서드
    func tableView(UITableView, didSelectRowAt: IndexPath)
    
    // 지정된 행의 선택이 해제되었음을 알리는 메서드
    func tableView(UITableView, didDeselectRowAt: IndexPath)
    
    // 특정 위치 행의 높이를 묻는 메서드
    func tableView(UITableView, heightForRowAt: IndexPath)
    
    // 특정 위치 행의 들여쓰기 수준을 묻는 메서드
    func tableView(UITableView, indentationLevelForRowAt: IndexPath)
    
    // 특정 섹션의 헤더뷰 또는 푸터뷰를 요청하는 메서드
    func tableView(UITableView, viewForHeaderInSection: Int)
    func tableView(UITableView, viewForFooterInSection: Int)
    
    // 특정 섹션의 헤더뷰 또는 푸터뷰의 높이를 물어보는 메서드
    func tableView(UITableView, heightForHeaderInSection: Int)
    func tableView(UITableView, heightForFooterInSection: Int)
    
    // 테이블뷰가 편집모드에 들어갔음을 알리는 메서드
    func tableView(UITableView, willBeginEditingRowAt: IndexPath)
    
    // 테이블뷰가 편집모드에서 빠져나왔음을 알리는 메서드
    func tableView(UITableView, didEndEditingRowAt: IndexPath?)

    UITableViewDataSource

  • ビュー付きデータソースオブジェクトUITableViewDataSourceプロトコル
  • を採用
  • データソースtableviewオブジェクトのテーブルビューの作成および変更に必要な情報
  • を提供する.
  • データソースは、テープビューの視覚的外観に関する最小情報
  • を提供するデータモデルのインクリメンタルゲートウェイである.
  • モデル-ビュー-コントローラ(MVC)設計モードにおいて、モデルに関連する
  • UItableViewオブジェクトに節数と行数を指定する、行の挿入、削除、並べ替えを選択的に実現する機能
  • がある.
    @required // 테이블 뷰를 만들기 위해서 반드시 필요한 메서드 
     // 특정 위치에 표시할 셀을 요청하는 메서드
     func tableView(UITableView, cellForRowAt: IndexPath) 
     
     // 각 섹션에 표시할 행의 개수를 묻는 메서드
     func tableView(UITableView, numberOfRowsInSection: Int)
     
     @optional
     // 테이블뷰의 총 섹션 개수를 묻는 메서드
     func numberOfSections(in: UITableView)
     
     // 특정 섹션의 헤더 혹은 푸터 타이틀을 묻는 메서드
     func tableView(UITableView, titleForHeaderInSection: Int)
     func tableView(UITableView, titleForFooterInSection: Int)
     
     // 특정 위치의 행을 삭제 또는 추가 요청하는 메서드
     func tableView(UITableView, commit: UITableViewCellEditingStyle, forRowAt: IndexPath)
     
     // 특정 위치의 행이 편집 가능한지 묻는 메서드
     func tableView(UITableView, canEditRowAt: IndexPath)
    
     // 특정 위치의 행을 재정렬 할 수 있는지 묻는 메서드
     func tableView(UITableView, canMoveRowAt: IndexPath)
     
     // 특정 위치의 행을 다른 위치로 옮기는 메서드
     func tableView(UITableView, moveRowAt: IndexPath, to: IndexPath)

    Delegate-DataSource関係



    [実施方法]


    [注意]


    https://velog.io/@yongchul/iOSTableView%EA%B4%80%EB%A0%A8-method%EC%9D%98-%EA%B8%B0%EB%8A%A5%EA%B3%BC-%EC%82%AC%EC%9A%A9%EB%B2%95