본문 바로가기

Swift

NavigationBar가 hidden일 경우 뒤로 가기

처음에 NavigationBar가 없을 때에는 self.dismissViewControllerAnimated(true, completion: nil)로 view를 닫았는데 NavigationBar를 달아놓으니 이게 안 먹는 것이다.

그런데 마침 이 View에서는 self.navigationController?.setNavigationBarHidden(true, animated: true) 상태라 뒤로 가기 버튼이 보이지 않는다.


검색을 좀 해 보니, 이런 경우에는 다음 함수를 이용해서 뒤로 갈 수 있다고 한다.

self.navigationController?.popViewControllerAnimated(true)


참고로 popView의 반대 개념은 self.navigationController?.pushViewController라고 한다.