I am trying to push a new view controller from the current controller with the push of a button. But as soon as the new controller is presented, the navigation bar from the top disappear and I have tried numerous ways but just cant seem to get it back.
I am doing all my code programmatically without any use of the Interface Builder.
I have tried the list of below codes but none of them worked.
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.setNavigationBarHidden(false, animated: false)
self.navigationItem.leftBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "backimg"), style: .plain, target: self, action: #selector(backTapped))
let webV:UIWebView = UIWebView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height))
webV.loadRequest(NSURLRequest(url: NSURL(string: "https://*****************.com")! as URL) as URLRequest)
webV.delegate = self;
self.view.addSubview(webV)
self.navigationController?.navigationBar.isHidden = false
navigationController?.isNavigationBarHidden = false
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(true)
self.navigationController?.navigationBar.isHidden = false
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(true)
self.navigationController?.navigationBar.isHidden = false
self.navigationController?.setNavigationBarHidden(false, animated: false)
}
@objc func backTapped(_ sender: Any){
self.dismiss(animated: true, completion: nil)
}
I am trying to push the view controller from the target function of the button as follows :
@objc func parkingTimerTapped(_ sender: Any) {
let pp = ParkingModeScheduleView()
self.present(pp, animated: true, completion: nil)
print("Parking Timer Tapped")
}
I have also already tried to push the view controller using the command below :
self.navigationController?.pushViewController(pp, animated: true)
Am I doing something wrong or missing something?
you need to add your parkingModeScheduleview in UINavigation controller like this
@objc func parkingTimerTapped(_ sender: Any) {
let pp = ParkingModeScheduleView()
let navigation = UINavigationController(rootViewController: pp)
self.present(navigation, animated: true, completion: nil)
print("Parking Timer Tapped")
}