Ch 04. To-Do List 앱 만들기

2 분 소요

Simulator Screen Shot - iPhone 11 Pro - 2022-04-07 at 18 32 12 Simulator Screen Shot - iPhone 11 Pro - 2022-04-07 at 18 32 21 Simulator Screen Shot - iPhone 11 Pro - 2022-04-07 at 18 33 07

기능 상세:
  • TableView 할 일 추가
  • TableView 할 일 삭제
  • TableView 할 일 재정렬
  • 할 일들을 데이터 저장소에 저장하여 앱을 재실행해도 데이터 유지
활용 기술:
  • UITableView
    데이터를 목록 형태로 보여 줄 수 있는 가장 기본적인 UI 컴포넌트
    • UIScrollView를 상속받아 수직으로 스크롤이 가능
    • 여러 개의 Cell을 가지고 있고 하나의 열과 여러 줄의 행을 지닌 리스트 형태
    • 섹션을 이용해 행을 그룹화하여 콘텐츠를 좀 더 쉽게 탐색
    • 섹션의 Header와 Futter에 view를 구성하여 추가적인 정보 표시

    • UITableView DataSource
      테이블 뷰를 생성하고 수정하는데 필요한 정보를 테이블 뷰 객체에 제공
    public protocol UITableViewDataSource : NSObjectProtocol  
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 각 세션에 표시할 행의 개수를 묻는 메서드
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell 특정 인덱스 Row의 Cell에 대한 정보를 넣어 Cell을 반환하는 메서드
    optional func numberOfSections(in tableView: UITableView) -> Int 총 섹션 개수를 묻는 메서드
    optional func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? 특정 섹션의 헤더 타이틀을 묻는 메서드
    optional func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? 특정 섹션의 푸터 타이틀을 묻는 메서드
    optional func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool 특정 위치의 행이 편집 가능한지 묻는 메서드
    optional func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool 특정 위치의 행을 재정렬 할 수 있는지 묻는 메서드
    optional func sectionIndexTitles(for tableView: UITableView) -> (String)? 테이블 뷰 섹션 인덱스 타이틀을 묻는 메서드
    optional func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int 인덱스에 해당하는 섹션을 알려주는 메서드
    optional func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) 스와이프 모드, 편집 모드에서 버튼을 선택하면 호출 되는 메서드
    해당 메서드에서는 행에 변경사항을 Commit 해야함
    optional func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) 행이 다른 위치로 이동되면 어디에서 어디로 이동했는지 알려주는 메서드
    • UITableView Delegate
      테이블 뷰의 시각적인 부분을 설정하고, 행의 액션 관리, 액세서리 뷰 지원 그리고 테이블 뷰의 개별 행 편집을 도움
    public protocol UITableViewDelegate : UIScrollViewDeligate  
    optional func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 행이 선택되었을 때 호출되는 메서드
    optional func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) 행이 선택 해체되었을 때 호출되는 메서드
    optional func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat 특정 위치 행의 높이를 묻는 메서드
    optional func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
    optional func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
    지정된 섹션의 헤더 뷰 또는 푸터뷰에 표시할 View 가 어떤 건지 묻는 메서드
    optional func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> CGFloat
    optional func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
    지정된 섹션의 헤더 뷰 또는 푸터뷰의 높이를 묻는 메서드
    optional func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) 테이블 뷰가 편집 모드에 들어갔을 때 호출되는 메서드
    optional func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) 테이블 뷰가 편집 모드에서 빠져나왔을 때 호출되는 메서드
    optional func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) 테이블 뷰가 셀을 사용하여 행을 그리기 직전에 호출되는 메서드
    optional func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) 테이블 뷰로부터 셀이 화면에 사라지면 호출되는 메서드
  • UIAlertController
    Alert창 표시
    • iOS에서 앱 또는 기기의 상태와 관련된 중요한 정보를 전달, 종종 사용자에게 피드백 요청
  • UserDefaults
    런타임 환경이 동작하면서 앱이 실행되는 동안 기본 저장소에 접근해 데이터를 기록하고 가져오는 역할
    • Key, Value를 쌍으로 저장(Dictionary - map)
    • 싱글톤 패턴으로 설계되어 앱 전체의 단 하나의 인스턴스만 존재
    • 기본적으로 제공하는 타입(float, int, double, boolean, url)과 NS관련 타입(NSData, NSString, NSNumber등)도 저장 가능

카테고리:

업데이트: