210319 Fri

Sunny·2021년 4월 3일
0

Today I Learned

목록 보기
15/88

1. 첫 번째 학습 내용: iOS View Life Cycle 다시 학습

UIViewController란? An object that manages a view hierarchy for your UIKit app.

class UIViewController : UIResponder

// 뷰가 메모리에 올려지는 순간
// 뷰가 화면에 보여지기 전에 생성되는 단계
    override func loadView() 

// 뷰가 화면에 보여지겠소
    override func viewWillAppear(_ animated: Bool)

A view controller’s main responsibilities include the following:

뷰 컨트롤러가 하는 일은?

  • Updating the contents of the views, usually in response to changes to the underlying data.
  • Responding to user interactions with views.
  • Resizing views and managing the layout of the overall interface.
  • Coordinating with other objects—including other view controllers—in your app.

Specify the views for a view controller using the loadView() method. In that method, create your view hierarchy programmatically and assign the root view of that hierarchy to the view controller’s view property.

메모리에 생긴다 = init
메모리에서 사라진다 = deinit

Figure 1 A sample navigation interface

A navigation controller object manages its child view controllers using an ordered array, known as the navigation stack. The first view controller in the array is the root view controller and represents the bottom of the stack. The last view controller in the array is the topmost item on the stack, and represents the view controller currently being displayed. You add and remove view controllers from the stack using segues or using the methods of this class. The user can also remove the topmost view controller using the back button in the navigation bar or using a left-edge swipe gesture.

2. 두 번째 학습 내용: Stepper 활용

UIStepper란? A control for incrementing or decrementing a value.

class UIStepper : UIControl

stepper의 옵션 중

  • wraps : 이게 True로 선언되면, 최대값이 될때 다시 최소값으로 바꾼다.
  • autorepeat : 누르고 있으면 반복해서 눌러진다라는 옵션??
  • maximumvalue : 최대값 설정

3. 세 번째 학습 내용: 화면 전환 및 뷰 사이의 데이터 공유

Segue란? 하나의 Scene 으로부터 다른 Scene으로의 전환을 보여주는 연결

Show (Push)

  • UINavigationViewController의 경우 Navigation Stack에 viewcontroller가 push된다.
  • 위의 NavigationBar의 Item을 보면 < Back 을 누르면 현재 viewcontroller가 pop된다.

Present Modally

  • viewcontroller를 modal로 보여주는 방식이다,
  • 이전 view를 가리는 새로운 view가 보여지는 방식이다.

데이터 전달 준비, prepare(for:sender:)

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        let destination = segue.destination
        guard let svc = destination as? StockAddViewController else { return }
        svc.juiceMachine = self.juiceMachine
    }

자체 프로퍼티인 destination을 통해 해당 세그의 목적지 뷰 컨트롤러를 추출할 수 있음.

해당 뷰컨트롤러가 실제 존재하는지 미리 확인하는 작업이 guard let 구문.

출처: iOS) Segue by 붱이

iOS 스토리보드 Segue로 뷰 컨트롤러간 데이터 전달 방법

profile
iOS Developer

0개의 댓글