UITabBarItem's title does not shown when using with Navigation controller
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
add a comment |
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
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
add a comment |
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
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
ios swift uitabbarcontroller uitabbaritem
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
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
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%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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
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.
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%2f53240530%2fuitabbaritems-title-does-not-shown-when-using-with-navigation-controller%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
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