IOS application/Swift

13. When viewDidAppear and viewWillAppear are not called.

개발자킹콩 2021. 5. 18. 07:29

When viewDidAppear and viewWillAppear are not called.

ViewController간의 이동을 한 뒤 다시 원래의 ViewController로 돌아오는 경우가 발생한다.

아래의 그림과 같이 ViewController에서 SecondViewController을 present하고 dismiss를 통해 다시 ViewController로 돌아오는 경우를 말한다. 이때 ViewController에서 viewDidAppear 과 viewWillAppear이 실행되지 않는 경우가 발생한다.

 

 

답은 fullScreen으로 불러오면 되는 것이다.

 

 

 

ViewController을 옮기게 되면 위의 그림과 같이 화면이 존재하는 상태로 위를 살짝 덮는 형태로 되어있고, 뒤에있는 View는 Appear이 유지되는 경우가 발생한다. 

@IBAction func loginButtonHandler(_ sender: Any) {
	let sb = UIStoryboard.init(name: "Login", bundle: nil)
	let vc = sb.instantiateViewController(identifier: "LoginViewController") as! LoginViewController
    vc.modalPresentationStyle = .fullScreen
    present(vc, animated: true, completion: nil)
}

 

다음코드와 같이 presentation style를 fullScreen으로 수정하면 된다.

 

 

 

 

'IOS application > Swift' 카테고리의 다른 글

15. 이용약관 동의 페이지  (0) 2021.05.21
14. Color Literal  (0) 2021.05.19
12. 선배가 알려주는 팁  (0) 2021.05.17
11. Crash between Swift Package and Cocoapods  (0) 2021.05.09
10. UIComponents 누가 위에 있나?  (0) 2021.04.30