私はこれまで同じ問題を抱えていましたが、これを解決するためにプログラムでナビゲーションバーを作成しました。これを行うには、関数を作成して関数をviewDidLoad
またはviewDidAppear
から呼び出します。
func addNavBar() {
let navigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height:54)) // Offset by 20 pixels vertically to take the status bar into account
navigationBar.barTintColor = UIColor.black
navigationBar.tintColor = UIColor.white
navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white]
// Create a navigation item with a title
let navigationItem = UINavigationItem()
navigationItem.title = "NavBarAppears!"
// Create left and right button for navigation item
let leftButton = UIBarButtonItem(title: "Back", style: .plain, target: self, action: #selector(btn_clicked(_:)))
let rightButton = UIBarButtonItem(title: "Right", style: .plain, target: self, action: nil)
// Create two buttons for the navigation item
navigationItem.leftBarButtonItem = leftButton
navigationItem.rightBarButtonItem = rightButton
// Assign the navigation item to the navigation bar
navigationBar.items = [navigationItem]
// Make the navigation bar a subview of the current view controller
self.view.addSubview(navigationBar)
}
func btn_clicked(_ sender: UIBarButtonItem) {
// Do something
performSegue(withIdentifier: "segueBackToHomeVC", sender: self)
}