0

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
}
Jake
  • 13,097
  • 9
  • 44
  • 73

1 Answers1

0

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.

Shad
  • 1,587
  • 2
  • 20
  • 29
  • this solved my problem. however, I don't think it would work in the case of another view controller coming onto the stack (such as a modal). that would cause the prompt to be empty upon returning to the last view controller. i'm still curious as to why this is happening... – Jake Jan 02 '17 at 09:16
  • I have no code setting the prompt other than what you suggested in viewWillDisappear. The prompt messages are all set in storyboard files. – Jake Jan 02 '17 at 10:04