iOS & Swift 공부 - UIViewController Lifecycle (영)

김영채 (Kevin)·2021년 2월 1일
0

iOS & Swift

목록 보기
63/107

viewWillAppear

override func viewDidLoad() {
	super.viewDidLoad() 
}
  • Called when content view created in memory

What is content view?

→ When you create a new view controller (cocoatoach class) in your storyboard, a View object is created automatically. The content view aforementioned is this.

viewWillAppear

override func viewWillAppear(_ animated: Bool){
	super.viewWillAppear(animated)
}
  • Called just before content view is added to app's view hierarchy

→ Doesn't necessarily mean that it will "appear" in the screen as you can call view.isHidden = true sometimes.

→ This method is called everytime we come back to the View Controller.

→ viewDidLoad only gets called once because it is called when it is stacked in the navigation controller memory.

viewDidAppear

override func viewDidAppear(_ animated: Bool){
	super.viewDidAppear(animated)
}
  • Called after the content view is added to app's view hierarchy

→ You might want to configure animations in this method. Animations might start a little bit too soon if you put animation related code in viewWillAppear or viewDidLoad.

viewWillDisappear

override func viewWillDisappear(_ animated: Bool){
	super.viewWillDisappear(animated)
}
  • Called before the content view is removed from the app's view hierarchy

→ Often used when you want to save some sort of data right before the user dismisses the view.

viewDidDisappear

override func viewDidDisappear(_ animated: Bool){
	super.viewDidDisappear(animated)
}
  • Called after the content view is removed from the app's view hierarchy
profile
맛있는 iOS 프로그래밍

0개의 댓글