UITableView, UIAlertController, UserDefaults (TodoList)

TodoList

활용 기술

  • UITableView
  • UIAlertController
  • UserDefaults

UITableView

데이터를 목록 형태로 보여 줄 수 있는 가장 기본적인 UI 컴포넌트 → UIScrollVIew 를 상속받고 있어서 스크롤 가능하다.

  • 여러개의 Cell을 가지고 있고 하나의 열과 여러 줄의 행을 지니고 있으며, 수직으로만 스크롤 가능하다.
  • 센션을 이용해 행을 그룹화하여 콘텐츠를 좀 더 쉽게 탐색할 수 있다.
  • 섹션의 헤더와 푸터에 View를 구성하여 추가적인 정보를 표시할 수 있다.

Delegate와 DataSource로 구성된다.

UITableViewDataSource : 테이블 뷰를 생성하고 수정하는데 필요한 정보를 테이블 뷰 객체에 제공, UITabelView 자체에서는 데이터를 관리하지 못한다.

UITableViewDelegate : 테이블 뷰의 시각적인 부분을 설정하고, 행의 액션 관리, 엑세서리 뷰 지원 그리고 테이블 뷰의 개별 행 편집을 도와줌

UIAlertController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@IBAction func tabBarAddButton(_ sender: UIBarButtonItem) {
let alert = UIAlertController(title: "할일 등록", message: nil, preferredStyle: .alert)
let registerButton = UIAlertAction(title: "등록", style: .default, handler: { [weak self] _ in
guard let title = alert.textFields?[0].text else { return }
let task = Task(title: title, done: false)
self?.tasks.append(task)
self?.tableView.reloadData()
})
let cancleButton = UIAlertAction(title: "취소", style: .cancel, handler: nil)
alert.addAction(cancleButton)
alert.addAction(registerButton)
alert.addTextField(configurationHandler: {textField in
textField.placeholder = "할 일을 입력해주세요"
})
self.present(alert, animated: true, completion: nil)

}

UIAlertContoller 로 alert 생성

UIAlertAction 으로 action button 정의

alert.addAction 으로 action button 추가하기 ,self 사용할떼 강한 순환참조 막기 위해서 weak 선언하기

alert.addTextField 로 alert에 textFiled 추가하가기

self.present 로 화면에 띄어주기

UserDefaults

런타임에 동작하여 기본 저장소에서 정보를 저장하거나 가져오는 기능을 한다. 키 값 형태로 값을 저장하고 싱글톤 패턴으로 구현되어서 앱내의 하나의 인스턴스만 존재한다.