[Swift iOS] viewDidAppear에서 한번만 호출하기

JB
Apr 28, 2021

--

보통 ViewController에 진입시 1번만 호출하려면

viewDidLoad 함수를 호출합니다.

그러나 viewWillAppear 이나 viewDidAppear 함수 안에서 1번만 호출하고싶으면

isBeingPresented OR isMovingToParent 의 Bool값으로 핸들링하면 됩니다.

isBeingPresented 값은 모달로 present 할 때,

isMovingToParent 값은 push 할 때

값이 true 가 됩니다

isBeingPresented
- this view controller is becoming visible because it is being presented from another view controller
isMovingToParent
- this view controller is becoming visible because it was just push onto a navigation controller or some other container view controller

(Rx를 쓰면 take 오퍼레이터를 통해 쉽게해결)

--

--

JB
JB

Written by JB

iOS engineer @kakaobank

No responses yet