UIViewController back button not shown

Multi tool use
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
//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
add a comment |
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
//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
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
add a comment |
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
//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
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
//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
ios swift
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
It seems maybe you can have another UINavigationController
between VCs like the following:
Hide the navigation bar of the first one. and use the second navigation bar as the root.
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
add a comment |
You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
It seems maybe you can have another UINavigationController
between VCs like the following:
Hide the navigation bar of the first one. and use the second navigation bar as the root.
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
add a comment |
It seems maybe you can have another UINavigationController
between VCs like the following:
Hide the navigation bar of the first one. and use the second navigation bar as the root.
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
add a comment |
It seems maybe you can have another UINavigationController
between VCs like the following:
Hide the navigation bar of the first one. and use the second navigation bar as the root.
It seems maybe you can have another UINavigationController
between VCs like the following:
Hide the navigation bar of the first one. and use the second navigation bar as the root.
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
add a comment |
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
add a comment |
You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.
add a comment |
You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.
add a comment |
You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.
You should check how you are presenting and popping VCs. There is a possibility that it's caused by something relating to that.
answered Dec 28 '18 at 7:45


iampikuda
111
111
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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