UIViewController back button not shown

Multi tool use
Multi tool use












0














rootViewController -> tabviewcontroller -> viewController1 -> viewController2



In such order, back button works fine but when viewController2 pops back to viewController1, viewController1's backbutton is not shown, so I cannot go back to tabviewcontroller.



What is the possible reason? Thanks for help.



Here is my storyboard



enter image description here



//after viewWillAppear
func initNavigation(){
//topItem is self.navigationController?.navigationBar.topItem
guard topItem != nil else {
return
}
//custom letButtonBar just make tabviewcontroller title at left
//other viewcontroller title is "" so position still at center
let leftButton = UIBarButtonItem(title: "", style:UIBarButtonItem.Style.plain, target: self, action: nil)
let attr = [NSAttributedString.Key.foregroundColor:UIColor.white, NSAttributedString.Key.font: UIFont(name: "iconfont", size: UIFont.buttonFontSize)!]

leftButton.setTitleTextAttributes(attr, for: .normal)
leftButton.setTitleTextAttributes(attr, for: .highlighted)
leftButton.setTitleTextAttributes(attr, for: .disabled)
leftButton.tintColor = UIColor.white
leftButton.isEnabled = false

topItem?.backBarButtonItem?.tintColor = UIColor.white
topItem?.setLeftBarButton(leftButton, animated: true)
topItem?.title = ""

}
//tabviewcontroller:
override func initNavigation() {
super.initNavigation()
topItem?.leftBarButtonItem?.title = "tabviewcontrollerTitleAtLeft"
}
//viewcontroller1
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController1TitleAtCenter"
}
//viewcontroller2
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController2TitleAtCenter"
}


I tried many times, found a solution, I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.










share|improve this question
























  • I think you call initNavigation in some wrong place in ViewController1. Also why do you not use backItem to change back button title?
    – Andrew Romanov
    Dec 28 '18 at 6:40










  • I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.
    – J.Kuai
    Jan 2 at 0:56


















0














rootViewController -> tabviewcontroller -> viewController1 -> viewController2



In such order, back button works fine but when viewController2 pops back to viewController1, viewController1's backbutton is not shown, so I cannot go back to tabviewcontroller.



What is the possible reason? Thanks for help.



Here is my storyboard



enter image description here



//after viewWillAppear
func initNavigation(){
//topItem is self.navigationController?.navigationBar.topItem
guard topItem != nil else {
return
}
//custom letButtonBar just make tabviewcontroller title at left
//other viewcontroller title is "" so position still at center
let leftButton = UIBarButtonItem(title: "", style:UIBarButtonItem.Style.plain, target: self, action: nil)
let attr = [NSAttributedString.Key.foregroundColor:UIColor.white, NSAttributedString.Key.font: UIFont(name: "iconfont", size: UIFont.buttonFontSize)!]

leftButton.setTitleTextAttributes(attr, for: .normal)
leftButton.setTitleTextAttributes(attr, for: .highlighted)
leftButton.setTitleTextAttributes(attr, for: .disabled)
leftButton.tintColor = UIColor.white
leftButton.isEnabled = false

topItem?.backBarButtonItem?.tintColor = UIColor.white
topItem?.setLeftBarButton(leftButton, animated: true)
topItem?.title = ""

}
//tabviewcontroller:
override func initNavigation() {
super.initNavigation()
topItem?.leftBarButtonItem?.title = "tabviewcontrollerTitleAtLeft"
}
//viewcontroller1
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController1TitleAtCenter"
}
//viewcontroller2
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController2TitleAtCenter"
}


I tried many times, found a solution, I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.










share|improve this question
























  • I think you call initNavigation in some wrong place in ViewController1. Also why do you not use backItem to change back button title?
    – Andrew Romanov
    Dec 28 '18 at 6:40










  • I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.
    – J.Kuai
    Jan 2 at 0:56
















0












0








0







rootViewController -> tabviewcontroller -> viewController1 -> viewController2



In such order, back button works fine but when viewController2 pops back to viewController1, viewController1's backbutton is not shown, so I cannot go back to tabviewcontroller.



What is the possible reason? Thanks for help.



Here is my storyboard



enter image description here



//after viewWillAppear
func initNavigation(){
//topItem is self.navigationController?.navigationBar.topItem
guard topItem != nil else {
return
}
//custom letButtonBar just make tabviewcontroller title at left
//other viewcontroller title is "" so position still at center
let leftButton = UIBarButtonItem(title: "", style:UIBarButtonItem.Style.plain, target: self, action: nil)
let attr = [NSAttributedString.Key.foregroundColor:UIColor.white, NSAttributedString.Key.font: UIFont(name: "iconfont", size: UIFont.buttonFontSize)!]

leftButton.setTitleTextAttributes(attr, for: .normal)
leftButton.setTitleTextAttributes(attr, for: .highlighted)
leftButton.setTitleTextAttributes(attr, for: .disabled)
leftButton.tintColor = UIColor.white
leftButton.isEnabled = false

topItem?.backBarButtonItem?.tintColor = UIColor.white
topItem?.setLeftBarButton(leftButton, animated: true)
topItem?.title = ""

}
//tabviewcontroller:
override func initNavigation() {
super.initNavigation()
topItem?.leftBarButtonItem?.title = "tabviewcontrollerTitleAtLeft"
}
//viewcontroller1
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController1TitleAtCenter"
}
//viewcontroller2
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController2TitleAtCenter"
}


I tried many times, found a solution, I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.










share|improve this question















rootViewController -> tabviewcontroller -> viewController1 -> viewController2



In such order, back button works fine but when viewController2 pops back to viewController1, viewController1's backbutton is not shown, so I cannot go back to tabviewcontroller.



What is the possible reason? Thanks for help.



Here is my storyboard



enter image description here



//after viewWillAppear
func initNavigation(){
//topItem is self.navigationController?.navigationBar.topItem
guard topItem != nil else {
return
}
//custom letButtonBar just make tabviewcontroller title at left
//other viewcontroller title is "" so position still at center
let leftButton = UIBarButtonItem(title: "", style:UIBarButtonItem.Style.plain, target: self, action: nil)
let attr = [NSAttributedString.Key.foregroundColor:UIColor.white, NSAttributedString.Key.font: UIFont(name: "iconfont", size: UIFont.buttonFontSize)!]

leftButton.setTitleTextAttributes(attr, for: .normal)
leftButton.setTitleTextAttributes(attr, for: .highlighted)
leftButton.setTitleTextAttributes(attr, for: .disabled)
leftButton.tintColor = UIColor.white
leftButton.isEnabled = false

topItem?.backBarButtonItem?.tintColor = UIColor.white
topItem?.setLeftBarButton(leftButton, animated: true)
topItem?.title = ""

}
//tabviewcontroller:
override func initNavigation() {
super.initNavigation()
topItem?.leftBarButtonItem?.title = "tabviewcontrollerTitleAtLeft"
}
//viewcontroller1
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController1TitleAtCenter"
}
//viewcontroller2
override func initNavigation() {
super.initNavigation()
self.navigationItem.title = "viewController2TitleAtCenter"
}


I tried many times, found a solution, I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.







ios swift






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 1:03

























asked Dec 28 '18 at 3:09









J.Kuai

113




113












  • I think you call initNavigation in some wrong place in ViewController1. Also why do you not use backItem to change back button title?
    – Andrew Romanov
    Dec 28 '18 at 6:40










  • I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.
    – J.Kuai
    Jan 2 at 0:56




















  • I think you call initNavigation in some wrong place in ViewController1. Also why do you not use backItem to change back button title?
    – Andrew Romanov
    Dec 28 '18 at 6:40










  • I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.
    – J.Kuai
    Jan 2 at 0:56


















I think you call initNavigation in some wrong place in ViewController1. Also why do you not use backItem to change back button title?
– Andrew Romanov
Dec 28 '18 at 6:40




I think you call initNavigation in some wrong place in ViewController1. Also why do you not use backItem to change back button title?
– Andrew Romanov
Dec 28 '18 at 6:40












I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.
– J.Kuai
Jan 2 at 0:56






I delete super.initNavigation() in viewcontroller1, it works fine finally, still do not know the reason.
– J.Kuai
Jan 2 at 0:56














2 Answers
2






active

oldest

votes


















0














It seems maybe you can have another UINavigationController between VCs like the following:



enter image description here



Hide the navigation bar of the first one. and use the second navigation bar as the root.






share|improve this answer























  • Not this reason. I check my code, only one UINavigationController, one RootViewController
    – J.Kuai
    Dec 28 '18 at 5:08










  • As I remember, you can't put one UINavigationController into other navigation controller. It will produce a crash in runtime.
    – Andrew Romanov
    Dec 28 '18 at 6:42










  • its not crash in this case. The second nav is a child of tab.
    – E.Coms
    Dec 28 '18 at 14:13



















0














You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53953256%2fuiviewcontroller-back-button-not-shown%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It seems maybe you can have another UINavigationController between VCs like the following:



    enter image description here



    Hide the navigation bar of the first one. and use the second navigation bar as the root.






    share|improve this answer























    • Not this reason. I check my code, only one UINavigationController, one RootViewController
      – J.Kuai
      Dec 28 '18 at 5:08










    • As I remember, you can't put one UINavigationController into other navigation controller. It will produce a crash in runtime.
      – Andrew Romanov
      Dec 28 '18 at 6:42










    • its not crash in this case. The second nav is a child of tab.
      – E.Coms
      Dec 28 '18 at 14:13
















    0














    It seems maybe you can have another UINavigationController between VCs like the following:



    enter image description here



    Hide the navigation bar of the first one. and use the second navigation bar as the root.






    share|improve this answer























    • Not this reason. I check my code, only one UINavigationController, one RootViewController
      – J.Kuai
      Dec 28 '18 at 5:08










    • As I remember, you can't put one UINavigationController into other navigation controller. It will produce a crash in runtime.
      – Andrew Romanov
      Dec 28 '18 at 6:42










    • its not crash in this case. The second nav is a child of tab.
      – E.Coms
      Dec 28 '18 at 14:13














    0












    0








    0






    It seems maybe you can have another UINavigationController between VCs like the following:



    enter image description here



    Hide the navigation bar of the first one. and use the second navigation bar as the root.






    share|improve this answer














    It seems maybe you can have another UINavigationController between VCs like the following:



    enter image description here



    Hide the navigation bar of the first one. and use the second navigation bar as the root.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 28 '18 at 6:12









    Raptor

    34.6k31175287




    34.6k31175287










    answered Dec 28 '18 at 3:50









    E.Coms

    1,6302412




    1,6302412












    • Not this reason. I check my code, only one UINavigationController, one RootViewController
      – J.Kuai
      Dec 28 '18 at 5:08










    • As I remember, you can't put one UINavigationController into other navigation controller. It will produce a crash in runtime.
      – Andrew Romanov
      Dec 28 '18 at 6:42










    • its not crash in this case. The second nav is a child of tab.
      – E.Coms
      Dec 28 '18 at 14:13


















    • Not this reason. I check my code, only one UINavigationController, one RootViewController
      – J.Kuai
      Dec 28 '18 at 5:08










    • As I remember, you can't put one UINavigationController into other navigation controller. It will produce a crash in runtime.
      – Andrew Romanov
      Dec 28 '18 at 6:42










    • its not crash in this case. The second nav is a child of tab.
      – E.Coms
      Dec 28 '18 at 14:13
















    Not this reason. I check my code, only one UINavigationController, one RootViewController
    – J.Kuai
    Dec 28 '18 at 5:08




    Not this reason. I check my code, only one UINavigationController, one RootViewController
    – J.Kuai
    Dec 28 '18 at 5:08












    As I remember, you can't put one UINavigationController into other navigation controller. It will produce a crash in runtime.
    – Andrew Romanov
    Dec 28 '18 at 6:42




    As I remember, you can't put one UINavigationController into other navigation controller. It will produce a crash in runtime.
    – Andrew Romanov
    Dec 28 '18 at 6:42












    its not crash in this case. The second nav is a child of tab.
    – E.Coms
    Dec 28 '18 at 14:13




    its not crash in this case. The second nav is a child of tab.
    – E.Coms
    Dec 28 '18 at 14:13













    0














    You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.






    share|improve this answer


























      0














      You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.






      share|improve this answer
























        0












        0








        0






        You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.






        share|improve this answer












        You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 28 '18 at 7:45









        iampikuda

        111




        111






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53953256%2fuiviewcontroller-back-button-not-shown%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            SE80 HQYmvGWW2,QUtWPD,coz,m2oME0R
            OM 95CTU RQI n66dUT9zlSzCzMSGH6ehf2M NYZ4BzEq9kU OhyjhXOYV LL7Yw2 7lNvUMuSSpLT vZk4y5 ID tO5K63J0G Yd04zeNEr

            Popular posts from this blog

            Monofisismo

            compose and upload a new article using a custom form

            “attempting to read past stream EOM” using Sybase.AdoNet4.AseClient