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










3














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 '18 at 15:50










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















3














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 '18 at 15:50










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













3












3








3


0





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 '18 at 18:19









Sateesh

1,9541715




1,9541715










asked Nov 10 '18 at 15:39









phuongzzzphuongzzz

237




237











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










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
















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










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















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




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












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




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












1 Answer
1






active

oldest

votes


















1














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 '18 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 '18 at 16:20










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






  • 1




    Very glad to help you and even I too forgot why its not working for a moment 😂.
    – Sateesh
    Nov 10 '18 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',
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%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









1














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 '18 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 '18 at 16:20










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






  • 1




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















1














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 '18 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 '18 at 16:20










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






  • 1




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













1












1








1






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 '18 at 16:15

























answered Nov 10 '18 at 16:05









SateeshSateesh

1,9541715




1,9541715







  • 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 '18 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 '18 at 16:20










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






  • 1




    Very glad to help you and even I too forgot why its not working for a moment 😂.
    – Sateesh
    Nov 10 '18 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 '18 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 '18 at 16:20










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






  • 1




    Very glad to help you and even I too forgot why its not working for a moment 😂.
    – Sateesh
    Nov 10 '18 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 '18 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 '18 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 '18 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 '18 at 16:20












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




Very detailed explanation!, thank you very much :)
– phuongzzz
Nov 10 '18 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 '18 at 16:33




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

















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.




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

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ

Node.js puppeteer - Use values from array in a loop to cycle through pages