뷰컨트롤러의 생명주기
iOS 의 대표적인 생명주기 2가지
1. 앱 생명주기
2. 뷰컨트롤러 생명주기
https://developer.apple.com/documentation/uikit/uiviewcontroller
UIViewController | Apple Developer Documentation
An object that manages a view hierarchy for your UIKit app.
developer.apple.com
https://developer.apple.com/documentation/uikit/app_and_environment/managing_your_app_s_life_cycle
Managing your app’s life cycle | Apple Developer Documentation
Respond to system notifications when your app is in the foreground or background, and handle other significant system-related events.
developer.apple.com
왜 알아야 하는가?
생명주기의 각 시점을 이해하고 원하는 시점에 필요한 기능을 구현하기 위함
ex) viewWillAppear 내에 랜덤 색상을 적용해주는 기능 구현
override func viewWillAppear(_ animated: Bool) {
print("viewWillAppear")
self.view.backgroundColor = UIColor(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1),
alpha: 1.0
)
self.button.backgroundColor = UIColor(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1),
alpha: 1.0
)
}
추가적으로 알면 좋은 내용
Drawing Cycle - 오토레이아웃, 프레임 등 화면을 그리는 생명주기
loadView() - 코드로 구현한 화면을 불러오기 위함, 뷰디드로드보다 먼저 실행
Your custom implementation of this method should not call super.
https://developer.apple.com/documentation/uikit/uiviewcontroller/1621454-loadview
loadView() | Apple Developer Documentation
Creates the view that the controller manages.
developer.apple.com
https://developer.apple.com/videos/play/wwdc2019/258/
Architecting Your App for Multiple Windows - WWDC19 - Videos - Apple Developer
Dive into the details about what it means to support multitasking in iOS 13. Understand how previous best practices fit together with new...
developer.apple.com
'내일배움캠프 iOS' 카테고리의 다른 글
UIKit) TIL # 33 메모리 관리 이해 (1) | 2024.12.04 |
---|---|
UIKit) TIL #32 MVC, Delegate Pattern (1) | 2024.12.03 |
UIKit) TIL #30 키오스크 팀프로젝트 마무리 - 아키텍처 , 오토레이아웃 충돌 intrinsicContentSize (0) | 2024.11.29 |
UIKit) TIL #29 키오스크 팀프로젝트 - 스크럼 (0) | 2024.11.28 |
UIKit) TIL #28 키오스크 팀프로젝트 Github - fork, upstream, fetch (1) | 2024.11.27 |