UITabBarItem's title does not shown when using with Navigation controller











up vote
3
down vote

favorite












I'm having a trouble with my very simple app.



My app simply have 2 mains UIViewControllers called News and Category, each of them has their own UINavigationController.



So in AppDelegate.swift, I've done like this



window = UIWindow(frame: UIScreen.main.bounds)
let tabBarController = UITabBarController()

let newsVC = NewsVC()

// CREATE TAB BAR ITEM WITH TITLE ONLY
let newsVCTabBarItem = UITabBarItem(title: "News", image: nil, tag: 1)
newsVC.tabBarItem = newsVCTabBarItem

let categoryVC = CategoryVC()

// CREATE TAB BAR ITEM WITH TITLE ONLY
let categoryVCTabBarItem = UITabBarItem(title: "Category", image: nil, tag: 2)
categoryVC.tabBarItem = categoryVCTabBarItem

let rootViewControllers = [newsVC, categoryVC]

// CREATE NAVIGATION CONTROLLER FOR EACH OF THEM
tabBarController.viewControllers = rootViewControllers.map {
UINavigationController(rootViewController: $0)
}
window?.rootViewController = tabBarController
window?.makeKeyAndVisible()


When I run this simple application, the tab bar items do not show anything :(



But when I change the UITabBarItem to system's styles like this



let newsVCTabBarItem = UITabBarItem(tabBarSystemItem: .featured, tag: 1)


It's working perfectly! So hard to understand!



So does anyone know why my title-only tab bar item does not working? Have I missed something important?



Thanks in advance!










share|improve this question
























  • Try to set the tabBarItem after put the viewcontroller in UINavigationController.
    – Sateesh
    Nov 10 at 15:50










  • I've tried your idea, but it's still does not work :(, anw, thanks for your help :)
    – phuongzzz
    Nov 10 at 15:53















up vote
3
down vote

favorite












I'm having a trouble with my very simple app.



My app simply have 2 mains UIViewControllers called News and Category, each of them has their own UINavigationController.



So in AppDelegate.swift, I've done like this



window = UIWindow(frame: UIScreen.main.bounds)
let tabBarController = UITabBarController()

let newsVC = NewsVC()

// CREATE TAB BAR ITEM WITH TITLE ONLY
let newsVCTabBarItem = UITabBarItem(title: "News", image: nil, tag: 1)
newsVC.tabBarItem = newsVCTabBarItem

let categoryVC = CategoryVC()

// CREATE TAB BAR ITEM WITH TITLE ONLY
let categoryVCTabBarItem = UITabBarItem(title: "Category", image: nil, tag: 2)
categoryVC.tabBarItem = categoryVCTabBarItem

let rootViewControllers = [newsVC, categoryVC]

// CREATE NAVIGATION CONTROLLER FOR EACH OF THEM
tabBarController.viewControllers = rootViewControllers.map {
UINavigationController(rootViewController: $0)
}
window?.rootViewController = tabBarController
window?.makeKeyAndVisible()


When I run this simple application, the tab bar items do not show anything :(



But when I change the UITabBarItem to system's styles like this



let newsVCTabBarItem = UITabBarItem(tabBarSystemItem: .featured, tag: 1)


It's working perfectly! So hard to understand!



So does anyone know why my title-only tab bar item does not working? Have I missed something important?



Thanks in advance!










share|improve this question
























  • Try to set the tabBarItem after put the viewcontroller in UINavigationController.
    – Sateesh
    Nov 10 at 15:50










  • I've tried your idea, but it's still does not work :(, anw, thanks for your help :)
    – phuongzzz
    Nov 10 at 15:53













up vote
3
down vote

favorite









up vote
3
down vote

favorite











I'm having a trouble with my very simple app.



My app simply have 2 mains UIViewControllers called News and Category, each of them has their own UINavigationController.



So in AppDelegate.swift, I've done like this



window = UIWindow(frame: UIScreen.main.bounds)
let tabBarController = UITabBarController()

let newsVC = NewsVC()

// CREATE TAB BAR ITEM WITH TITLE ONLY
let newsVCTabBarItem = UITabBarItem(title: "News", image: nil, tag: 1)
newsVC.tabBarItem = newsVCTabBarItem

let categoryVC = CategoryVC()

// CREATE TAB BAR ITEM WITH TITLE ONLY
let categoryVCTabBarItem = UITabBarItem(title: "Category", image: nil, tag: 2)
categoryVC.tabBarItem = categoryVCTabBarItem

let rootViewControllers = [newsVC, categoryVC]

// CREATE NAVIGATION CONTROLLER FOR EACH OF THEM
tabBarController.viewControllers = rootViewControllers.map {
UINavigationController(rootViewController: $0)
}
window?.rootViewController = tabBarController
window?.makeKeyAndVisible()


When I run this simple application, the tab bar items do not show anything :(



But when I change the UITabBarItem to system's styles like this



let newsVCTabBarItem = UITabBarItem(tabBarSystemItem: .featured, tag: 1)


It's working perfectly! So hard to understand!



So does anyone know why my title-only tab bar item does not working? Have I missed something important?



Thanks in advance!










share|improve this question















I'm having a trouble with my very simple app.



My app simply have 2 mains UIViewControllers called News and Category, each of them has their own UINavigationController.



So in AppDelegate.swift, I've done like this



window = UIWindow(frame: UIScreen.main.bounds)
let tabBarController = UITabBarController()

let newsVC = NewsVC()

// CREATE TAB BAR ITEM WITH TITLE ONLY
let newsVCTabBarItem = UITabBarItem(title: "News", image: nil, tag: 1)
newsVC.tabBarItem = newsVCTabBarItem

let categoryVC = CategoryVC()

// CREATE TAB BAR ITEM WITH TITLE ONLY
let categoryVCTabBarItem = UITabBarItem(title: "Category", image: nil, tag: 2)
categoryVC.tabBarItem = categoryVCTabBarItem

let rootViewControllers = [newsVC, categoryVC]

// CREATE NAVIGATION CONTROLLER FOR EACH OF THEM
tabBarController.viewControllers = rootViewControllers.map {
UINavigationController(rootViewController: $0)
}
window?.rootViewController = tabBarController
window?.makeKeyAndVisible()


When I run this simple application, the tab bar items do not show anything :(



But when I change the UITabBarItem to system's styles like this



let newsVCTabBarItem = UITabBarItem(tabBarSystemItem: .featured, tag: 1)


It's working perfectly! So hard to understand!



So does anyone know why my title-only tab bar item does not working? Have I missed something important?



Thanks in advance!







ios swift uitabbarcontroller uitabbaritem






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 18:19









Sateesh

1,226615




1,226615










asked Nov 10 at 15:39









phuongzzz

207




207












  • Try to set the tabBarItem after put the viewcontroller in UINavigationController.
    – Sateesh
    Nov 10 at 15:50










  • I've tried your idea, but it's still does not work :(, anw, thanks for your help :)
    – phuongzzz
    Nov 10 at 15:53


















  • Try to set the tabBarItem after put the viewcontroller in UINavigationController.
    – Sateesh
    Nov 10 at 15:50










  • I've tried your idea, but it's still does not work :(, anw, thanks for your help :)
    – phuongzzz
    Nov 10 at 15:53
















Try to set the tabBarItem after put the viewcontroller in UINavigationController.
– Sateesh
Nov 10 at 15:50




Try to set the tabBarItem after put the viewcontroller in UINavigationController.
– Sateesh
Nov 10 at 15:50












I've tried your idea, but it's still does not work :(, anw, thanks for your help :)
– phuongzzz
Nov 10 at 15:53




I've tried your idea, but it's still does not work :(, anw, thanks for your help :)
– phuongzzz
Nov 10 at 15:53












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Add title property to the ViewControllers to show the title in UITabBarItem.



var title: String? { get set }



Set the title to a human-readable string that describes the view. If
the view controller has a valid navigation item or tab-bar item,
assigning a value to this property updates the title text of those
objects.




let newsVC = ViewController()
newsVC.title = "News"

.....

let categoryVC = ViewController2()
categoryVC.title = "Category"

.....


Or



Assign an image to the UITabBarItem to see the result.



let newsVCTabBarItem = UITabBarItem(title: "News", image: UIImage(named: "news.png"), tag: 1)

....

let categoryVCTabBarItem = UITabBarItem(title: "Category", image: UIImage(named: "category.png"), tag: 2)

.....


Update:




Tab bar items are configured through their corresponding view
controller. To associate a tab bar item with a view controller, create
a new instance of the UITabBarItem class, configure it appropriately
for the view controller, and assign it to the view controller’s
tabBarItem property. If you don't provide a custom tab bar item for
your view controller, the view controller creates a default item
containing no image and the text from the view controller’s title
property.







share|improve this answer



















  • 1




    Cool! It's worked, but I still confusing, if I set the view controller's title different from the ui tab bar item, it show the VC's title (but not the one I've set in ui tab bar item), so the name in ui tab bar item seem useless?
    – phuongzzz
    Nov 10 at 16:08








  • 1




    Yes it is. If we do not provide the image for the tabBarItem it takes title property of ViewController. So, the first answer only shows the title of the tabBarItem. If we provide image along with title then UITabBarController considers UITabBarItems.
    – Sateesh
    Nov 10 at 16:20










  • Very detailed explanation!, thank you very much :)
    – phuongzzz
    Nov 10 at 16:31






  • 1




    Very glad to help you and even I too forgot why its not working for a moment 😂.
    – Sateesh
    Nov 10 at 16:33











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',
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%2f53240530%2fuitabbaritems-title-does-not-shown-when-using-with-navigation-controller%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Add title property to the ViewControllers to show the title in UITabBarItem.



var title: String? { get set }



Set the title to a human-readable string that describes the view. If
the view controller has a valid navigation item or tab-bar item,
assigning a value to this property updates the title text of those
objects.




let newsVC = ViewController()
newsVC.title = "News"

.....

let categoryVC = ViewController2()
categoryVC.title = "Category"

.....


Or



Assign an image to the UITabBarItem to see the result.



let newsVCTabBarItem = UITabBarItem(title: "News", image: UIImage(named: "news.png"), tag: 1)

....

let categoryVCTabBarItem = UITabBarItem(title: "Category", image: UIImage(named: "category.png"), tag: 2)

.....


Update:




Tab bar items are configured through their corresponding view
controller. To associate a tab bar item with a view controller, create
a new instance of the UITabBarItem class, configure it appropriately
for the view controller, and assign it to the view controller’s
tabBarItem property. If you don't provide a custom tab bar item for
your view controller, the view controller creates a default item
containing no image and the text from the view controller’s title
property.







share|improve this answer



















  • 1




    Cool! It's worked, but I still confusing, if I set the view controller's title different from the ui tab bar item, it show the VC's title (but not the one I've set in ui tab bar item), so the name in ui tab bar item seem useless?
    – phuongzzz
    Nov 10 at 16:08








  • 1




    Yes it is. If we do not provide the image for the tabBarItem it takes title property of ViewController. So, the first answer only shows the title of the tabBarItem. If we provide image along with title then UITabBarController considers UITabBarItems.
    – Sateesh
    Nov 10 at 16:20










  • Very detailed explanation!, thank you very much :)
    – phuongzzz
    Nov 10 at 16:31






  • 1




    Very glad to help you and even I too forgot why its not working for a moment 😂.
    – Sateesh
    Nov 10 at 16:33















up vote
1
down vote



accepted










Add title property to the ViewControllers to show the title in UITabBarItem.



var title: String? { get set }



Set the title to a human-readable string that describes the view. If
the view controller has a valid navigation item or tab-bar item,
assigning a value to this property updates the title text of those
objects.




let newsVC = ViewController()
newsVC.title = "News"

.....

let categoryVC = ViewController2()
categoryVC.title = "Category"

.....


Or



Assign an image to the UITabBarItem to see the result.



let newsVCTabBarItem = UITabBarItem(title: "News", image: UIImage(named: "news.png"), tag: 1)

....

let categoryVCTabBarItem = UITabBarItem(title: "Category", image: UIImage(named: "category.png"), tag: 2)

.....


Update:




Tab bar items are configured through their corresponding view
controller. To associate a tab bar item with a view controller, create
a new instance of the UITabBarItem class, configure it appropriately
for the view controller, and assign it to the view controller’s
tabBarItem property. If you don't provide a custom tab bar item for
your view controller, the view controller creates a default item
containing no image and the text from the view controller’s title
property.







share|improve this answer



















  • 1




    Cool! It's worked, but I still confusing, if I set the view controller's title different from the ui tab bar item, it show the VC's title (but not the one I've set in ui tab bar item), so the name in ui tab bar item seem useless?
    – phuongzzz
    Nov 10 at 16:08








  • 1




    Yes it is. If we do not provide the image for the tabBarItem it takes title property of ViewController. So, the first answer only shows the title of the tabBarItem. If we provide image along with title then UITabBarController considers UITabBarItems.
    – Sateesh
    Nov 10 at 16:20










  • Very detailed explanation!, thank you very much :)
    – phuongzzz
    Nov 10 at 16:31






  • 1




    Very glad to help you and even I too forgot why its not working for a moment 😂.
    – Sateesh
    Nov 10 at 16:33













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Add title property to the ViewControllers to show the title in UITabBarItem.



var title: String? { get set }



Set the title to a human-readable string that describes the view. If
the view controller has a valid navigation item or tab-bar item,
assigning a value to this property updates the title text of those
objects.




let newsVC = ViewController()
newsVC.title = "News"

.....

let categoryVC = ViewController2()
categoryVC.title = "Category"

.....


Or



Assign an image to the UITabBarItem to see the result.



let newsVCTabBarItem = UITabBarItem(title: "News", image: UIImage(named: "news.png"), tag: 1)

....

let categoryVCTabBarItem = UITabBarItem(title: "Category", image: UIImage(named: "category.png"), tag: 2)

.....


Update:




Tab bar items are configured through their corresponding view
controller. To associate a tab bar item with a view controller, create
a new instance of the UITabBarItem class, configure it appropriately
for the view controller, and assign it to the view controller’s
tabBarItem property. If you don't provide a custom tab bar item for
your view controller, the view controller creates a default item
containing no image and the text from the view controller’s title
property.







share|improve this answer














Add title property to the ViewControllers to show the title in UITabBarItem.



var title: String? { get set }



Set the title to a human-readable string that describes the view. If
the view controller has a valid navigation item or tab-bar item,
assigning a value to this property updates the title text of those
objects.




let newsVC = ViewController()
newsVC.title = "News"

.....

let categoryVC = ViewController2()
categoryVC.title = "Category"

.....


Or



Assign an image to the UITabBarItem to see the result.



let newsVCTabBarItem = UITabBarItem(title: "News", image: UIImage(named: "news.png"), tag: 1)

....

let categoryVCTabBarItem = UITabBarItem(title: "Category", image: UIImage(named: "category.png"), tag: 2)

.....


Update:




Tab bar items are configured through their corresponding view
controller. To associate a tab bar item with a view controller, create
a new instance of the UITabBarItem class, configure it appropriately
for the view controller, and assign it to the view controller’s
tabBarItem property. If you don't provide a custom tab bar item for
your view controller, the view controller creates a default item
containing no image and the text from the view controller’s title
property.








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 10 at 16:15

























answered Nov 10 at 16:05









Sateesh

1,226615




1,226615








  • 1




    Cool! It's worked, but I still confusing, if I set the view controller's title different from the ui tab bar item, it show the VC's title (but not the one I've set in ui tab bar item), so the name in ui tab bar item seem useless?
    – phuongzzz
    Nov 10 at 16:08








  • 1




    Yes it is. If we do not provide the image for the tabBarItem it takes title property of ViewController. So, the first answer only shows the title of the tabBarItem. If we provide image along with title then UITabBarController considers UITabBarItems.
    – Sateesh
    Nov 10 at 16:20










  • Very detailed explanation!, thank you very much :)
    – phuongzzz
    Nov 10 at 16:31






  • 1




    Very glad to help you and even I too forgot why its not working for a moment 😂.
    – Sateesh
    Nov 10 at 16:33














  • 1




    Cool! It's worked, but I still confusing, if I set the view controller's title different from the ui tab bar item, it show the VC's title (but not the one I've set in ui tab bar item), so the name in ui tab bar item seem useless?
    – phuongzzz
    Nov 10 at 16:08








  • 1




    Yes it is. If we do not provide the image for the tabBarItem it takes title property of ViewController. So, the first answer only shows the title of the tabBarItem. If we provide image along with title then UITabBarController considers UITabBarItems.
    – Sateesh
    Nov 10 at 16:20










  • Very detailed explanation!, thank you very much :)
    – phuongzzz
    Nov 10 at 16:31






  • 1




    Very glad to help you and even I too forgot why its not working for a moment 😂.
    – Sateesh
    Nov 10 at 16:33








1




1




Cool! It's worked, but I still confusing, if I set the view controller's title different from the ui tab bar item, it show the VC's title (but not the one I've set in ui tab bar item), so the name in ui tab bar item seem useless?
– phuongzzz
Nov 10 at 16:08






Cool! It's worked, but I still confusing, if I set the view controller's title different from the ui tab bar item, it show the VC's title (but not the one I've set in ui tab bar item), so the name in ui tab bar item seem useless?
– phuongzzz
Nov 10 at 16:08






1




1




Yes it is. If we do not provide the image for the tabBarItem it takes title property of ViewController. So, the first answer only shows the title of the tabBarItem. If we provide image along with title then UITabBarController considers UITabBarItems.
– Sateesh
Nov 10 at 16:20




Yes it is. If we do not provide the image for the tabBarItem it takes title property of ViewController. So, the first answer only shows the title of the tabBarItem. If we provide image along with title then UITabBarController considers UITabBarItems.
– Sateesh
Nov 10 at 16:20












Very detailed explanation!, thank you very much :)
– phuongzzz
Nov 10 at 16:31




Very detailed explanation!, thank you very much :)
– phuongzzz
Nov 10 at 16:31




1




1




Very glad to help you and even I too forgot why its not working for a moment 😂.
– Sateesh
Nov 10 at 16:33




Very glad to help you and even I too forgot why its not working for a moment 😂.
– Sateesh
Nov 10 at 16:33


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53240530%2fuitabbaritems-title-does-not-shown-when-using-with-navigation-controller%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







Popular posts from this blog

The Sandy Post

Danny Elfman

Pages that link to "Head v. Amoskeag Manufacturing Co."