view controller의 생명주기

이태혁·2021년 5월 5일
0
post-thumbnail

  • viewDidLoad()

    Called after the controller's view is loaded into memory.

컨트롤러의 뷰가 메모리에 로드된 후에 호출된다.

view가 로드되는 처음 한번만 실행됨

  • viewWillAppear(_:)

    Notifies the view controller that its view is about to be added to a view hierarchy.

뷰가 뷰 hierarchy에 추가되기 직전에 호출된다.

viewDidLoad와 viewWillAppear의 차이

둘의 차이는 화면이 여러개일 때 나타난다.
뷰를 처음 보여졌을 때는 viewDidLoad와 ViewWillAppear가 둘다 호출되지만 다른 화면을 갔다가 돌아왔을때는 viewWillAppear만 호출된다.

  • viewDidAppear(_:)

    Notifies the view controller that its view was added to a view hierarchy.

뷰가 나타난 뒤에 호출된다.

  • viewWillDisappear(_:)
    Notifies the view controller that its view is about to be removed from a view hierarchy.

뷰가 사라지기 직전에 호출된다.

  • viewDidDisappear(_:)

    Notifies the view controller that its view was removed from a view hierarchy.

뷰가 사리지고 난 뒤에 호출된다.

  • viewDidUnload의 경우 사용불가인것 같다.

출처

profile
back-end, cloud, docker, web의 관심이 있는 예비개발자입니다.

0개의 댓글