gpt4 book ai didi

swift - 在 Swift 中,导航栏消失并且永远不会回来

转载 作者:搜寻专家 更新时间:2023-10-31 22:24:13 26 4
gpt4 key购买 nike

我正在尝试通过按下按钮从当前 Controller 推送一个新的 View Controller 。但是新 Controller 一出现,顶部的导航栏就消失了,我尝试了很多方法,但似乎无法恢复。

我在不使用 Interface Builder 的情况下以编程方式编写所有代码。

我已经尝试了下面的代码列表,但没有一个有效。

  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)

}

我正在尝试从按钮的目标函数中推送 View Controller ,如下所示:

  @objc func parkingTimerTapped(_ sender: Any) {
let pp = ParkingModeScheduleView()

self.present(pp, animated: true, completion: nil)
print("Parking Timer Tapped")
}

我也已经尝试使用以下命令推送 View Controller :

  self.navigationController?.pushViewController(pp, animated: true)

我是不是做错了什么或遗漏了什么?

最佳答案

你需要像这样在 UINavigation Controller 中添加你的 parkingModeScheduleview

@objc func parkingTimerTapped(_ sender: Any) {
let pp = ParkingModeScheduleView()
let navigation = UINavigationController(rootViewController: pp)
self.present(navigation, animated: true, completion: nil)
print("Parking Timer Tapped")
}

关于swift - 在 Swift 中,导航栏消失并且永远不会回来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55585466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com