popToRootViewController not removing prompt

721 views Asked by At

I have an app that prompts the user for various information before doing a task. Once all the information is put in by the user, I do a UIApplication.shared.openUrl(url: url) and then self.navigationController?.popToRootViewController(animated: true). The app pops back to the root view controller; however, the navigation item prompt from the last view controller is now included in the navigation item of the root view controller.

Anyone understand why this is happening and a good way to fix it? I could just set the prompt to "" when the root view controller reappears, but I would like to solve the problem, not alleviate the symptom.

Update

Per @Shad 's answer, I've updated my view controller with the code below and everything is working as expected.

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)    
    self.navigationItem.prompt = nil
}
1

There are 1 answers

2
Shad On BEST ANSWER

The reason is that your prompts is added to window and is visible even the parent View-Controller, on which the prompts was added, is not currently visible. We can go on details if you share some code.

However there is a way to dismiss the prompts before going back to RootViewController. You can use the -(void) viewWillDisappear:(BOOL)animated to dismiss the prompts. Just remove the prompts view from the parent View-Controller by calling removeFromSuperview() on the -(void) viewWillDisappear:(BOOL)animated. Assuming your prompts is a UIView.