Trulyawesome
TodoApp 제작(Swift)1 본문
개발자라면 거의 다 만들어보는 TodoList를 만들어 보았다. 처음에는 아주 쉽게? 생각했는데 은근히 까다로웠다,,
-구현기능
1.Todo 입력
2.Todo 삭제
3.Todo 자세히 보기
4.달력보기
5.달력 일자 다중선택
-사용기술
1.TableView
2.Swift 5.0
3.MVC
4.Koyomi(Calendar)
5.Toolbar
6.navigation controller
MVC ( Model)
모델은 Calander, Todo 2개를 만들어보았습니다.
https://github.com/shoheiyokoyama/Koyomi 에 캘린더 사용법이 친절하게 나와있어요 참고합시다.^.^
Todomodel에는 title과 내용인 contents를 만들어 주고 init을 작성해줍니다. 모델링이 끝나면 viewcontroller을 작성해봅시다.
navigation controller을 만들어 주시고 tableView 작성을 해줍시다. 그리고 Mainstoryboard에 들어가 tableView와 Controller연결을 해줍시다.(DataSource, Delegate)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
extension TodoViewController: UITableViewDataSource {
//cell count
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return todoList.count
}
//cell present
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? TodoCell else {return UITableViewCell()}
cell.title.text = todoList[indexPath.row].title
cell.title.preferredMaxLayoutWidth = 150
cell.layer.cornerRadius = 10
cell.title.numberOfLines = 0
return cell
}
]
|
cs |
extension을 이용해서 구현하였습니다. 먼저 tableViewDataSource는 이렇게 작성해주었습니다. 그리고 controller class 부분을 구현해 보면
1
2
3
4
5
6
7
|
import UIKit
var todoList: [Todo] = []
class TodoViewController: UIViewController {
@IBOutlet var TodoListView: UITableView!
|
cs |
Todo를 todoList에 다담아줄겁니다. 쓰기 편하게 전역변수로 선언해줍니다.
또 tableView타입의 변수를 만들어 아울렛을 연결해줍니다.
이렇게 하면 기본적인 틀은 대충 만들어 졌습니다.
'프로그래밍 > iOS' 카테고리의 다른 글
TodoApp 제작(Swift)2 (0) | 2020.01.24 |
---|---|
Swift Userdefault로 데이터 저장하기 (0) | 2020.01.21 |
Firebase 데이터 입력 및 불러오기 (0) | 2019.12.29 |
Firebase 설정하기 (0) | 2019.12.28 |
iOS HTML 데이터 가져오기 (1) | 2019.12.28 |