MyPageViewController에서 프로필 변경 화면으로 전환할 때, ProfileChangeViewController를 아래 코드와 같이 호출하게 된다. (modal 형식)
// 프로필 설정 버튼 클릭 시 호출
@objc private func showProfileChangeView() {
let profileChangeVC = ProfileChangeViewController()
profileChangeVC.selectedProfileTypeIdx = selectedProfileTypeIdx
profileChangeVC.modalPresentationStyle = .formSheet
self.present(profileChangeVC, animated: true)
}
ProfileChangeViewController에서 프로필 타입 값을 수정한 뒤 저장 버튼을 누르면,
꼼꼼한 재은씨 책에서 공부한대로 self.presentingViewController 로 현재 뷰 컨트롤러(ProfileChangeViewController)를 표시해주고 있는 뷰 컨트롤러(MyPageViewController)를 참조해서 MyPageViewController의 selectedProfileType 프로퍼티 값을 변경해준 뒤, **dismiss()**를 수행해주면 잘 될 줄 알았다.
(VC2에서는 현재의 뷰 컨트롤러를 화면에 표시해주고 있는 뷰 컨트롤러를 가리키는 presentingViewController 속성을 통해 이전 화면을 참조해준다. )
그래서 ProfileChangeViewController에서 저장 버튼을 눌렀을 때 호출되는 메서드를 아래와 같이 구성해주었다.
// [저장] 버튼을 눌렀을 때 동작
@objc private func performProfileUpdate() {
**guard let myPageVC = self.presentingViewController as? MyPageViewController else {
return
}
myPageVC.selectedProfileType = selectedProfileType**
// 파이어베이스 DB에 수정된 프로필 타입 저장
firebaseManager.updateUserProfileType(type: ProfileType.allCases[selectedProfileTypeIdx])
**self.dismiss(animated: true)**
}
하지만 해당 코드는 동작을 하지 않았다.
그리고 한 번 MyPageViewController와 ProfileChangeViewController의 viewWillAppear() 메서드가 호출되는 시점도 확인을 해봤는데
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
...(중략)...
**print("마이페이지 뷰 컨트롤러!!")**
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
**print("프로필 수정 뷰 컨트롤러!!")**
}

ProfieChangeViewController 화면이 나타난 뒤 다시 닫아줘도 MyPageViewController의 viewWillAppear()가 호출되지 않는 것을 발견했다.