I'm new, I have NavigationController with ViewController , and view with my CurrencyViewController controller, and in DialogViewController , in which there are 4 DLRadioButton, when I click, I process the event for the previous view, using the code self.performSegue(withIdentifier: "close", sender: self) (yes, segue tied) I get the transition but the navigation bar disappears, tell me how to deal with it? What I tried:

  1. In the lifecycle controller tried navigationController?.setNavigationBarHidden
  2. Used such

let controller = UIStoryboard (name: "Main", bundle: Bundle.main) .instantiateViewController (withIdentifier: "close")

enter image description here

Tried in such functions

 override func viewWillAppear(_ animated: Bool) { self.navigationController?.setNavigationBarHidden(false, animated: true) } override func viewWillDisappear(_ animated: Bool) { super.viewWillDisappear(animated) navigationController?.setNavigationBarHidden(false, animated: false) } 
  • Inside which function do you use setNavigationBarHidden? Can you give more code? - Ivan Kramarchuk
  • Above added code, called in CurrencyViewController and DialogViewController - GR1995 5:19 pm
  • Please show the full call code of CurrencyViewController too. And in general, can you ideally make an example and put it on a GitHub? Because The reasons may be different. - Ivan Kramarchuk

1 answer 1

Here the problem is rather in architecture, and not in functions. After you have displayed the currency selection window, do not use performSegue for a new call to CurrencyViewController.

Instead, you must transfer the value of the selected currency through the protocol, Singleton or NotificationCenter, and close the selection window.

Method via protocol:

Add the closeProtocol file:

 protocol closeProtocol { func closeModal() var selectedCurrency: String? { get set } } 

Indicate that CurrencyViewController should implement closeProtocol:

 class CurrencyViewController: UIViewController,UIPickerViewDelegate, closeProtocol 

In DialogViewController add:

 var delegate: closeProtocol? 

In CurrencyViewController add:

 var popVC: DialogViewController? var selectedCurrency: String? 

And change the beginning of the tapped () function to:

 self.popVC = storyboard?.instantiateViewController(withIdentifier: "popVC") as! DialogViewController popVC?.modalPresentationStyle = .popover popVC?.delegate = self 

Add the closeModal () function to CurrencyViewController:

 func closeModal() { labelcurrencyDestination = self.selectedCurrency ?? "Гривна" currency.text = labelcurrencyDestination popVC?.dismiss(animated: true, completion: nil) } 

Change SelectCurrency in DialogViewController to:

 @IBAction func selectCurrency(_ sender: DLRadioButton) { delegate?.selectedCurrency = sender.titleLabel?.text delegate?.closeModal() } 

What will be the result: When choosing a currency, you via the delegate transfer the selected currency to the main screen and send the command to close the pop-up window to the same screen.

  • Thank you very much for your help and explanation, everything works) - GR1995