How to connect the UITabBarController to 3 different screens? - ios

I just created the UITabBarController and then I embedded the NavigationController into it.
The issue I am having now is that I am not sure how to add tab bar items. Right now I just have one item that goes to the home screen. But what do I do to add tabs to that tabbarcontroller?
I tried control-dragging it to other controllers, but I think that is not the way to go here.
Could someone please point me in the right direction.

Tab bar items are automatically added based on how many view controllers the UITabBarController has.
For example when you call:
self.tabBarController.viewControllers = #[viewController1, viewController2];
2 tab bar items will be created automatically for you.

I assume you're using Storyboards.
If you right click on the Tab Bar view controller connections icon (the round golden icon on the left) or select the connections inspector (on the right) while you've got your navigation controller selected in the storyboard you'll see a "View Controllers" option under "Triggered Segues". Simply drag from that circle to the new view controller you want to be linked in your tab bar controller and voila, new tab bar item.

You can also do all of that from the beginning. If you start a project that is a tabbar project you will automatically get two tabs. If you want more, drag a view controller over from the right pane under objects. Then control click and drag from the root view to the new view controller and select relationship tabbar. You can hook up as many as you want without the code. Hope this helps you out.

Related

show another storyboard as the content of 1st tab of TabBarController

I have a tab bar controller in storyboard like below:
I have anther storyboard which I would like to use as the content of 1st tab. Let's call it Content.storyboard
What I want to achieve is:
I would like the content of the 1st tab of Tab Bar Controller to be the Content.storyboard.
What I tried is:
I removed the default 1st view controller from Tab Bar Controller storyboard and added a storyboard reference connecting from Tab Bar Controller to Content.storyboard, like below:
The problem is , as you see above, I lost the ability to edit the Tab Item.
So, what is the correct way to achieve what I want? (That's showing a view from another storyboard as content of a tab of TabBarController)
I ran into an issue similar to this recently. I ended up moving the navigation controller out of the separate storyboard and into the main storyboard and configured the tab bar items there.
EDIT
After some further testing, it looks like the storyboard reference node gets a fake tab bar item. You can't delete it or modify it.
To provide the tab bar item for the other view controller, go into that storyboard and set the view controllers simulated metrics to Translucent tab bar:
Then you can drag in a tab bar item from the object library:
I chose the Bookmarks system icon. you won't see this reflected in the main storyboard, but you will at runtime (and on the child storyboard).
You can achieve this using container view
1) Take Container view in your tab
2) Delete added viewcontroller window (Usually come with container view )
3) Add storyboard Reference
4) Drag from container view to storyboard Reference choose embed option
I have also faced the same issue:
Follow the step:
Go to your Content.storyboard
Expand your initial view controller.
then -
After that:

Adding new tabs to a tab bar controller

I am creating a tab bar iOS app. The tab bar view controller has two tabs, each of them connected to a view controller.
This how it looks:
I need to add more tabs to the tab controller. I am doing it at the storyboard as follows:
I add a new view controller.
I control-drag from the tab bar controller to the new created view controller.
A window opens and I select Relationship Segue-View Controller.
The segue from the tab bar controller to the new view controller is created.
I think that is the way to do it, but after that the tab bar controller doesn't show any tab icons, the tab bar becomes grey.
Like this:
I need to know what am I doing wrong.
First drag A TabBarController from Object Library you see that only two tabs with thier VC there.
to add more Tab Item in TabBarVC drag VC from Object Library
Then Control drag from TabBarVC to Newly VC then Segue relation pop ups
Select last one Relationship Segue -> View Controllers
I had the same problem until I added a tab bar item from the object library into the new view (settings its attributes on the right hand panel) and THEN ctrl dragged from the tab bar controller to the new view, creating a relationship segue.
If I tried to ctrl drag from the tab controller without first adding a tab item to the new view, it had the behaviour you described.
be sure to check the size of your icon image.
the tint of image added is grey by default. If you have a large sized tab bar image, it can look like the whole tab bar is greyed out for some reason. pic does not auto resize.
bellow process is follow in Xcode 9.4 for adding new item in tab bar controller.
1)Drag and Drop new Tab Bar Controller into sotrtyboard
2)It will show 2 item which connected with 2 view controller.
3)For adding third item button in tab bar controller
i) Add new View Controller.
ii) Right click on Tab Bar Controller and Drag into new view controller.
iii) one option popup will display inside that popup select "view controllers" options
It will create relationship link and will generate automatic item button in tab bar controller.
need to add/drag icon (from showing the media library) to the 3rd view controller, so that it can display properly.
Restarting Xcode 6.1.1 solved the issue for me while I was working on multiple projects.
go t0 library and choose tabbar controller then drag and drop after that take another uiviewcontroller and then click on tabbar and control and right click then drag and drop in the uiviewcontroller then you see some options where you have to choose in the relationship segue -> view controller
for more clearance see these images

Xcode - How to attach a tab bar to a view without adding a tab for the new view

I have an application which has 5 tabs. I also have another view which you can access from tab3 via a selection of buttons. I will call it view 3b. View 3b populates with information based on which button the user selected in view 3. After the user puts in all the information required the app automatically takes them back to view 3. I want to add the tab bar to this view(3b) but I do not want it to have its own tab. I just want to use it so the user can navigate out of this view back to the rest of the app if they want to exit the screen early. Does anyone know how I can attach the tab bar to this screen without having a tab added for this screen. I am using Xcode 4.6.2 and am using storyboards to set up my app.
Any help would be appreciated. I've done a bit of searching but everything I find just explains how to use tabs.
Any help would be appreciated. Thanks.
It sounds like you need to use a UINavigationController.
When you set up your UITabBarController, instead of linking the third tab directly to your 3rd view controller, connect it to a UINavigationController, and then set the root view of that UINavigationController as the UIViewController you want as your third tab.
From there, you can set up your buttons to perform a push segue to your second view controller (view 3b from your question). If you do this, not only will you keep the tab bar on view 3b, but a back button will automatically be placed in the top left of the page so the user can simply go back to view 3. If you don't want the navigation bar that appears to be there, you can instead uncheck the "shows navigation bar" checkbox in the UINavigationController's attributes inspector.
I hope this helps!

How to go from a single view to a tab bar view

need some help here
My problem is, my app starts with a single view, it shows a menu made with buttons that takes me to different places, one of this places is another kind of menu, but this menu is a tab bar menu, so the thing is, I made a new file with its .xib, I added the tab bar controller, and i Linked all the sections of my tabs with its viewcontrollers...
this means that I have my first menu ready, I have my view controllers ready, I have my menu on the tab bar ready....
so my problem is...
how can I go from my single view (the first view that I see and that doesnt include a tab bar), to the new screen with tab bar controller in it after pressing a button???
help me please
Note: I'm using XCode 4.2 and I'm not working with storyboards (requirements of the app)
You have three options to show your viewController content :
1.using presentModalViewController:
2.add the viewController view as a subView to the current viewController. in your case : [singleViewController.view addSubView:tabBarViewController.view];
3.or if your simple ViewController is the navigation root viewController you can push other viewControllers to its navigation stack. (as #roronoa zorro described).
You might have added all the next viewControllers on the taBarController so if you have want to tabbar on to next screen you simplr have to push the tabbarcontroller on the navigationcontroller.
[self.navigationController pushViewController:TabBarControllerObj];

Trying to add 3rd tab to tabBarController

I'm trying to add a 3rd tab to the tabBarController using ios5. The standard object you get when you drag it out to your storyboard has 2 tabs. Does anyone know how to do this? I searched the internet and all examples start with their tabBarController with the extra tabs without showing how to get it.
Here is the video I watched that taught me how to add a third tab to a TabBarController:
Tab bar for Xcode Swift for iOS
I will summarize the process below.
Create a new Tabbed Application project
This will automatically provide two tabs that already "just work".
Add new View Controller
Drag another view controller onto the storyboard.
Add Tab Bar Item
Drag a Tab Bar Item onto the new View Controller that you just added.
Connect to Tab View Controller
Click and Control-Drag from the Tab View Controller to your new View Controller. A menu will pop up. Choose the view controllers option under the Relationship Segue group.
That's it. You should be able to run it now and have all three tabs work. Watch the video that I linked to for more details.
Note:
To do anything on your new tab, don't forget to add a new View Controller class (as you would for any new View Controller).
Based on Wolvorin and Tom van responses, and based on what I have experienced you should do as following:
Create an empty View Controller (in Controllers and Objects)
From Windows and Bars, drag Tab Bar Item to the newly added view
From the main View Controller, select Tab Bar Controller icon (next to First Responder), and Control-Drag to the newly added View
BOOM you have new tab
To expound on #Roozbeh 's answer, when you control drag from the Tab Bar Controller to the newly added view controller, make sure you select the view controller option under Relationship Seque
I was reading this question after having the same problem and I wanted to clarify what the exact step was.
for third tab first add a view controller and then right click the tabview controller and then from it's storyboard segway from relation controll drag to the added view controller and it's done
Look in the right part of the screen, I believe it's the Objects library view. Just find the "Tab Item" (or something) and drag it into the bar.

Resources