简体   繁体   中英

UIPageViewController change navigation bar back button title

This is my complete code . In PageViewController navigation not working

Here when I click button in view controller of page view controller , it will navigate to next view (Final View Controller). Now i want to change the navigation bar back button .

在此处输入图片说明

See in above image when i click button in ViewController [View controller will load in PageViewController] it will navigate to FinalViewController

My code for navigation bar title 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)


}

But this code not working

The back button belongs to the previous view controller, not the one currently presented on screen. you can use delegate or segue see this

This answer working fine...

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM