38
iOS iOS 개개 개개 2016.06.28 개개개

iOS 앱 개발 강의 자료 #2

Embed Size (px)

Citation preview

Page 1: iOS 앱 개발 강의 자료 #2

iOSiOS 개발개발2016.06.28

모정훈

Page 2: iOS 앱 개발 강의 자료 #2

목차- Auto Layout 복습- 샘플 앱 소개와 관련 학습 내용- Table View Controller- Tab Bar View Controller- Navigation Controller- To-Do App 제작 ( 실습 )

- Tabbar, Navigation Controller, List, Simple animation

- Catalog App 제작 ( 실습 )- Load from plist, Tabbar, Navigation Controller, List, Detail

Page 3: iOS 앱 개발 강의 자료 #2

To-Do App0 To-Do App

- Tabbar, Navigation Controller, List, Simple animation

Page 4: iOS 앱 개발 강의 자료 #2

Catalog App0 Catalog App

- Load from plist, Tabbar, Navigation Controller, List, Detail

Page 5: iOS 앱 개발 강의 자료 #2

Auto Layout0 Example

Page 6: iOS 앱 개발 강의 자료 #2

Sample Source #10 01.AppLifeCycle

- AppLifeCycleObjectiveC (Objective-C 작성 )- AppLifeCycleSwift (Swift 작성 )

0 02.HelloWorlds- HelloWorldObjectiveC (Objective-C 작성 )- HelloWorldSwift (Swift 작성 )

0 03.StoryBoards- StoryBoardSwift01 (Segue 의 3 가지 방식 샘플 )- StoryBoardSwift02 ( 다른 Storyboard 파일의 ViewController 로드 )

0 04.AutoLayout- AutoLayoutSwift

0 05.XIBvsNoneXIB- NoneIBTabbar (XIB 없이 코드로 Tabbar 작성 )- StoryBoardTabbar (IB/StoryBoard 로 Tabbar 작성 )

Page 7: iOS 앱 개발 강의 자료 #2

Sample Source #20 01.TestTableViewSwift

- TableView, Delegate/DataSource 이해- https://github.com/picomax/TableViewSwift

0 02.TodoMemoSwift- 데이터 저장 (UserDefaults), 화면전환 이해- https://github.com/picomax/TodoMemo

0 03.CatalogSwift- Tabbar Controller, Key/Value 코딩의 이해- https://github.com/picomax/Catalog

Page 8: iOS 앱 개발 강의 자료 #2

View Controller0 Controller (vs. View)

- public func viewWillAppear (animated: Bool)- public func viewDidAppear (animated: Bool)- public func viewWillDisappear (animated: Bool)- public func viewDidDisappear (animated: Bool)- public func viewWillLayoutSubviews ()- public func viewDidLayoutSubviews ()

.

.

.

Page 9: iOS 앱 개발 강의 자료 #2

Class Hierarchy0 Hierarchy

- NSObject

Page 10: iOS 앱 개발 강의 자료 #2

View Hierarchy0 UIWindow0 UIViewController0 UIView

Page 11: iOS 앱 개발 강의 자료 #2

Table View0 Table View

Page 12: iOS 앱 개발 강의 자료 #2

Table View Cell0 Table View Cell

Page 13: iOS 앱 개발 강의 자료 #2

Table View Controller0 DataSource 주요 함수 및 실행 순서

- numberOfSectionInTableView:- tableView:numberOfRowsInSection:- tableView:cellForRowAtIndexPath:

Page 14: iOS 앱 개발 강의 자료 #2

Table View Controller0 DataSource

Page 15: iOS 앱 개발 강의 자료 #2

Table View Controller0 Delegate

- 객체의 불필요한 상속을 피하고 ,- 메소드를 재정의 하지 않음으로써 좀 더 객체 지향적인 ..

Page 16: iOS 앱 개발 강의 자료 #2

Table View Controller0 Drag

- editingStyleForRowAtIndexPath- canEditRowAtIndexPath

0 Delete- commitEditingStyle

Page 17: iOS 앱 개발 강의 자료 #2

Table View Controller0 UITableViewDataSource

- RequiredtableView(tableView: UITableView, numberOfRowsInSection section: Int) -> InttableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

- OptionalnumberOfSectionsInTableView(tableView: UITableView) -> InttableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String?

// EditingtableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool

// Moving/reorderingtableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool

// IndexsectionIndexTitlesForTableView(tableView: UITableView) -> [String]?tableView(tableView: UITableView, sectionForSectionIndexTitle title: String, atIndex index: Int) -> Int

// Data manipulation - insert and delete supporttableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)

// Data manipulation - reorder / moving supporttableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath)

Page 18: iOS 앱 개발 강의 자료 #2

Table View Controller0 UITableViewDelegate

- Optional// Display customizationtableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath)...

// Variable height supporttableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat...

// SelectiontableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)...

// EditingtableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle...tableView(tableView: UITableView, titleForDeleteConfirmationButtonForRowAtIndexPath indexPath: NSIndexPath) -> String?

.

.

.

Page 19: iOS 앱 개발 강의 자료 #2

Example App #10 Project 생성0 TableView 생성 -> Delegate, DataSource 연결0 TableView -> TableViewCell 생성 (title, subtitle 추가 )0 ViewController -> Delegate, DataSource 코드 작성

- tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int- tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

0 Data 생성 , DataSource 연결var items: [String] = ["Egg Benedict", "Mushroom Risotto”, "Full Breakfast", "Hamburger",

"Ham and Egg Sandwich", "Creme Brelee", "White Chocolate Donut", "Starbucks Coffee","Vegetable Curry", "Instant Noodle with Egg”, "Noodle with BBQ Pork","Japanese Noodle with Pork”, "Green Tea", "Thai Shrimp Cake", "Angry Birds Cake","Ham and Cheese Panini"]

Page 20: iOS 앱 개발 강의 자료 #2

Navigation Controller0 Navigation Bar0 Custom content0 Navigation Toolbar

Page 21: iOS 앱 개발 강의 자료 #2

Navigation Controller0 UINavigationController0 presentedViewController0 pushViewController

Page 22: iOS 앱 개발 강의 자료 #2

Navigation Controller0 Navigation Controller0 RootViewController0 Navigation Bar0 Bar Button Item0 Navigation Toolbar

Page 23: iOS 앱 개발 강의 자료 #2

Navigation Controller0 pushViewController0 popViewController

Page 24: iOS 앱 개발 강의 자료 #2

To-Do App0 To-Do App

- Tabbar, Navigation Controller, List, Simple animation

Page 25: iOS 앱 개발 강의 자료 #2

To-Do App #10 TaskModel

- title: String- memo: String- done: String

0 TaskListManager (singleton)- taskModelArray- saveAll()- loadAll() or modelAtIndex(i)

0 ListViewController- taskListManager.taskModelArray 출력- textLabel, detailTextLabel, accessoryType- delete, move item.

0 EditViewController- taskModel 생성- taskListManager.taskModelArray.append(model)

Page 26: iOS 앱 개발 강의 자료 #2

To-Do App #20 Singleton Pattern

- 하나의 인스턴스- 어디서든 접근 가능- 리스트 자체를 관리 (get/set for key from list)

0 UserDefaults- Library/Preferences/{appID}.plist- NSData, NSString, NSNumber, NSDate, NSArray, NSDictionary- or Serialization (NSKeyedArchiver/NSKeyedUnarchiver)

0 Serialization- flatMap

0 dequeueReusableCellWithIdentifier- TableViewCell 재사용

Page 27: iOS 앱 개발 강의 자료 #2

To-Do App #30 Project 생성0 Storyboard -> NavigationController 추가

- 기본 TableViewController 를 ViewController 로 교체- RootViewController 지정- NavigationBar -> Bar Button Item (Left / Right) 추가- Left Bar Button Item -> Edit 속성 변경- Right Bar Button Item -> Add 속성 변경

0 TableView 생성- delegate, dataSource 연결- Table View -> Table View Cell 생성 (title, subtitle 추가 )

0 View Controller -> Delegate, DataSource 코드 작성- taskManager.loadAll()- taskManager.taskModelArray 연동

Page 28: iOS 앱 개발 강의 자료 #2

To-Do App #40 EditViewController 생성

- Navigation Item 생성- Navigation Item -> Bar Button Item 추가- Right Bar Button Item -> Done 속성 변경- Done 버튼 -> 함수 연결

0 EditViewController -> TextField (title/subtitle) 추가- Done 함수와 title/subtitle 필드 연동- TaskModel 생성 후 TaskManager.append()

Page 29: iOS 앱 개발 강의 자료 #2

Catalog App0 Catalog App

- Load from plist, Tabbar, Navigation Controller, List, Detail

Page 30: iOS 앱 개발 강의 자료 #2

Catalog App #10 Image Resource, Plist Data

- 리소스 파일 다운로드- https://db.tt/ssZptzKv

0 CatalogInfo.plist- Dictionary 타입의 데이터 파일- 프로젝트 디렉토리에 복사 후 Drag & Drop

0 images- 이미지 리소스 폴더- 프로젝트 내 Assets.xcassets 내부로 Drag & Drop

Page 31: iOS 앱 개발 강의 자료 #2

Catalog App #20 CatalogModel

- title: String, subtitle, desc, homepage, …

0 CatalogListManager (singleton)- catalogModelArray- catalogModelAtIndex(i)

0 CatalogListViewController- taskListManager.taskModelArray 출력- textLabel, detailTextLabel, accessoryType- delete, move item.

0 DetailViewController0 IntroViewViewController

- taskModel 생성- taskListManager.taskModelArray.append(model)

Page 32: iOS 앱 개발 강의 자료 #2

Catalog App #30 Plist 로드

- let path = NSBundle.mainBundle().pathForResource("CatalogInfo", ofType: "plist")!- self.infoArray = NSArray(contentsOfFile: path)!

0 Key/Value Coding.- NSObject.valueForKey(key)- NSObject.setValue(value, forKey:key)- NSObject.setValue(value, forKeyPath:classPath)- dictionary = from.dictionaryWithValuesForKeys(keys:[“a”, “b”, “c”, …])

0 Block coding in swift vs ObjectiveC{ (parameters) -> return type in

statements}

0 scrollView.contentSize- height = CGRectGetMakeY( lastObject.frame )

Page 33: iOS 앱 개발 강의 자료 #2

Catalog App #40 Project 생성

- 기존 ViewController 제거

0 Tab Bar Controller 추가- Tab 이름 / 아이콘 설정

0 Intro Tab Bar- Intro -> Scroll View 추가- IntroViewController.swift 생성 / Scene 연결- Scroll View -> intro image 적용

0 AppInfo Tab Bar- AppInfo -> Image View 추가- Appinfo image 적용

Page 34: iOS 앱 개발 강의 자료 #2

Catalog App #50 Navigation Controller 추가

- 기존 연결된 TableViewController 제거- Tab Bar Controller 연결- Tab 이름 / 아이콘 설정

0 View Controller 생성- Navigation Controller 의 rootViewController 연결- CatalogListViewController.swift 생성 후 연결

0 TableView 생성- delegate, dataSource 연결- Table View -> Table View Cell 생성 (image:120x85, label, tag 추가 )- catalogListManager 와 dataSource delegate 연결 코드 작성- Table View Cell 높이 설정 height : 85

Page 35: iOS 앱 개발 강의 자료 #2

Catalog App #60 View Controller 생성

- image(4:3), thumbnail, label, score 컴포넌트 생성- DetailViewController.swift 생성 후 연결- CatalogModel 연동 코드 작성

0 prepareForSegue 연결- CatalogListViewController 과 DetailViewController 연결 코드 작성- CatalogModel 데이터 전달

Page 36: iOS 앱 개발 강의 자료 #2

Test Code0 XCTestCase 객체를 상속하여 File 생성

- CatalogTests : XCTestCase {}- 테스트할 대상과 유사한 파일 명으로 생성후 값 / 함수 테스트

0 Target 지정- 테스트 시 사용할 객체를 지정- Singleton 객체의 경우 테스트 전 로드

0테스트 전 , 후 수행할 코드 작성- setUp()- tearDown()

0테스트 함수 작성- test + 테스트 명 ()

Page 37: iOS 앱 개발 강의 자료 #2

Q & A0 Thank You

Page 38: iOS 앱 개발 강의 자료 #2

Thank you# Contact

- www.picomax.net- @picomax- [email protected]