UIPageViewController 更改导航栏后退按钮标题
UIPageViewController change navigation bar back button title
这是我的完整代码。
在这里,当我在页面视图控制器的视图控制器中单击按钮时,它将导航到下一个视图(最终视图控制器)。现在我想更改导航栏后退按钮。
当我单击 ViewController 中的按钮时,如上图所示 [View controller 将加载到 PageViewController] 它将导航到 FinalViewController
我的导航栏标题代码ViewController:
@IBAction func btn(_ sender: Any) {
print("ViewController one")
print(variable)
let storyboard = self.storyboard?.instantiateViewController(withIdentifier: "FVC")
let backItem = UIBarButtonItem()
backItem.title = "Final VC"
// self.navigationItem.backBarButtonItem = backItem
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.self.navigationBar.backItem?.backBarButtonItem = backItem
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.pushViewController(storyboard!, animated: true)
}
但是这段代码不起作用
后退按钮属于前一个视图控制器,而不是当前显示在屏幕上的视图控制器。
你可以使用委托或 segue
见
这个答案工作正常...
let storyboard = self.storyboard?.instantiateViewController(withIdentifier: "FVC")
let backButton = UIBarButtonItem()
backButton.title = "name"
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.self.navigationBar.topItem?.backBarButtonItem = backButton
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.pushViewController(storyboard!, animated: true)
这是我的完整代码。
在这里,当我在页面视图控制器的视图控制器中单击按钮时,它将导航到下一个视图(最终视图控制器)。现在我想更改导航栏后退按钮。
当我单击 ViewController 中的按钮时,如上图所示 [View controller 将加载到 PageViewController] 它将导航到 FinalViewController
我的导航栏标题代码ViewController:
@IBAction func btn(_ sender: Any) {
print("ViewController one")
print(variable)
let storyboard = self.storyboard?.instantiateViewController(withIdentifier: "FVC")
let backItem = UIBarButtonItem()
backItem.title = "Final VC"
// self.navigationItem.backBarButtonItem = backItem
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.self.navigationBar.backItem?.backBarButtonItem = backItem
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.pushViewController(storyboard!, animated: true)
}
但是这段代码不起作用
后退按钮属于前一个视图控制器,而不是当前显示在屏幕上的视图控制器。
你可以使用委托或 segue
见
这个答案工作正常...
let storyboard = self.storyboard?.instantiateViewController(withIdentifier: "FVC")
let backButton = UIBarButtonItem()
backButton.title = "name"
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.self.navigationBar.topItem?.backBarButtonItem = backButton
(UIApplication.shared.keyWindow?.rootViewController as? UINavigationController)?.pushViewController(storyboard!, animated: true)