Lets imagine the scenario:
UITabBarController
- UITabBar
- Tab 1: View Controller A
- Tab 2: View Controller B
When I click on View Controller A I want to push another UITabBarController:
UITabBarController
-UITabBar
- Tab 1: View Controller 1
- Tab 2: View Controller 2
- Tab 3: View Controller 3
Is this possible? To have a UITabBarController push another UITabBarController onto the view stack?
You can certainly do this but I would rethink your design. Selecting a UITabBar item and changing the Tab Bar itself goes against Human Interface Guidelines. Besides, in your example, how do you get back to the root view controller?
Perhaps you should use a UITableView that when you tap a cell it pushes a view controller containing a UITabBarController (technically this might go against HIG too since a tab bar should be the same throughout an entire app but I've had plenty of apps adopt this and it seems elegant). So using your example:
RootViewController:
pushed as UINavigationController with a UITableView containing two cells:
"cell1" & "cell2"
-Tapping on "cell1" pushes a view controller containing UITabBar(I) which contains "View Controller A" and "View Controller B."
-Tapping on "cell2" pushes a view controller containing UITabBar(II) which contains "View Controller 1," "View Controller 2," and "View Controller 3."
In each case, you get a "back" button and the UITabBar itself doesn't have to change.
Sure, I just stacked them up in interface builder. There's some frame offsetting issues, but you can see tabbars stacked up. Additionally, the tabbars unstack when other tabs are selected. I also had to make sure the first tab's view was added to the window's view and connected as an IBOutlet, but otherwise that should do it.
Related
I have an iOS app written in Swift with UITabBarController with 5 UIViewControllers. Now, I have a bunch of UIViewControllers that are not part of the UITabBarController. I'd like to be able to show that same tabbar but I have no idea how to do that. Any clue?
More details: This is one of the View Controllers that the tabbar has. I use storyboard references and split my view controllers into separate more manageable storyboards.
So, the big picture:
There's no initial ViewController since I use storyboardId to get to the initial Navigation Controller. From there we have a ViewController embedded in the same Navigation controller. In that ViewController, there are 2 Container views - one of the size of the bottom ViewController that contains the "hamburger" button that toggles the other Container View which has an embedded UITableView in. When a specific cell is selected it should go to Profile ViewController that's not even in the same storyboard. The segue is set to be Push. Either way, doesn't show the UITabBar on the Profile ViewController
how you doing?
I don't know if I understood, but you are trying to show tabbar after going to another screen, right? If the answer is 'yes', try to change your segue to show(e.g. push).
-----Edit-----
You can do with two ways:
Presenting Modally -> using Current Context
Use push(e.g.) with a navigation view controller, you can also hide the navigation bar if you go to Navigation controller -> Attributes inspector -> Navigation Controller -> Uncheck Shows Navigation Bar
Hope now it works!
Best regards
I have a tab bar controller that points to several story board references.
One of the references points to a story board (SC1) with two view controllers. On VC1, the tab bar appears, yet on VC2 the tab bar does not when I segue to it programmatically. Perhaps it's more accurate to say the tab bar items don't because a light grey bar does appear to be at the bottom of the view.
I have another story board (SC2) with a similar setup yet the tab bar appears on both VC1 and VC2. In this case I segue by clicking on a tableview cell.
In both cases I segue from VC1 to VC2 using a Show (e.g. Push) segue.
it needs to be created as a relationship to the external storyboard reference. the storyboard's VC you'll be referencing must have a tab bar item in it to show app. Plus you can also try create a tab bar controller and add them in code (I have done that in the past).
The issue was a lack of understanding of Tab Bar Controller and the relationship with Navigation View Controllers.
I assumed every child vc embedded in a Tab Bar Controller would display the tabs. In other words..
Tab vc
...vc1
.....vc2
Tab vc only sees vc1. The answer is in the Navigation Controller.
The first vc must be embedded in a Navigation Controller. That vc and all other child vc's go onto the Nav Controller stack... When you call it, every child vc knows that it is embedded in a Tab Vc and will display the tabs.
So I have this application where I have a view controller (which I want to appear first when the app starts) and a tab bar controller. I also have other navigation bar controllers that are in the tab bar controller. I want to place my view controller on top of the tab bar controller. Making the tab bar controller the parent of the view controller would be better though.
But take note, I do not want a tab bar item to represent the view controller and I want the tab bar to appear along with the view controller. I do not and would not want to use storyboards as much as possible. How can i achieve this?
I guess the simplest solution would be to use a screenshot of your tabBar and put it in your HomeViewController as a button. In this case you could use your HomeViewController as rootViewController and in the button action you set the TabBarController as the rootViewController.
Root = Home + Button
-->
Root = TabBar
Perhaps you need four buttons, if you want the correct tab to be selected.
I have an iPhone / iPad application that manages its numerous view controllers via a UINavigationController and UITabViewController. The UINavigationController handles the majority of the user interaction and the UITabViewController handles user settings/preferences.
My app delegate initializes the UINavigationController and pushes the first view controller. Settings (the UITabViewController) can be accessed via a button on the navigation controller's menu bar; the user can return to the main application (the UINavigationController) via a button on the UITabViewController.
My question is: what should I be doing with the UINavigationController (and its stack of view controllers) when I show the UITabViewController and vice-versa? Is there any reason to remove/release/recreate each parent controller as the user switches between the two, or should I be adding/removing each parent controller's view to my app's window?
It seems that the first option would be more mindful of memory/resources, however these benefits might get overshadowed by the processing cost to re-alloc/init the view controllers each time.
Thanks.
You do not have to manage the navigation controller's stack manually. What I would do is present your settings view controller as a modal view. You would do this at the navigation controller level.
Assume that settingsViewController is a property of your main view controller.
self.settingsViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal
[self.navigationController presentModalViewController:self.settingsViewController animated:YES];
I assume you mean UITabBarController.
If your navigation view would show up in the tab view for a tab item, I would suggest let the tab bar controller to be the root view controller of your application (and therefore always seen in the app).
If your navigation view is the main view, and the user simply opens up the tab bar view for settings etc. and will return for the navigation view, then modally presenting the tab bar controller is the right way.
In the first case (the navigation controller IN the tab bar controller), you would not care for adding/removing or allocating/releasing views as the UIKit will manage it for you.
In the second case you may create a tab bar controller when you want to show it. presentModalViewController will retain the view controller so you can release it immediately after you send the message. If you want to hold the view controller then you create one when the application is loaded and retain it in the navigation controller (and the navigation controller will always remain in the memory).
I have a tabbar application. Second tab had a drill down table list with Navigation Controller. I also want to implement a segmented control inside a tool bar that shows different table entries as per the selected switch in segmented control. I am a little confused as to how to implement this?
Screen-shot -
This is the view in second tab controller an instance of the generic UIViewController. Blue Background is a UIView that contains a segmented control (1,2,3,4). The steel blue navigation bar at the top is a simulated UI Element from Interface Builder. I need to put a navigation Controller such that it has a list table view that changed depending on the switch selected in segmented control UI.
I have following options
Add UINavController as root controller for second tab directly with table view inside it. In that case how do I accomodate the UIToolbar having segmented control?
I add UISegmentedControl as part of the view of Second Tab's view controller and add navigation based table view as another element to that view. Is this doable? How can I add a nav based controller to a UIView and control the frame so that it does not cover the UIToolBar.
I hope I am making sense. Please lemme know if you have any suggestions. Thanks.
This is how I achieved it. In IB, in MainWindow.xib where I have a tabbarController, I made the class identity of the second tab to a UINavigationConrtroller. Then I made the main view Controller for second tab that had the segmented control and the Table View as a rootViewController to the NavigationController. This functioning exactly as I wanted. Thanks all for your help.
you can add UINavigationController in place of UIViewController in UITabbarcontroller and Put your UIViewController who haveing UISegmentControl in UInavigationController who add in UITabbarcontroller
in reading its looks confusing but try to implement its work
Step 1: xcode-->new Project-->tabbar application
Step 2: open xib of main window select tabbarcontroller and open inspector. in that you able to see list of view controllers change their class to uinavigationController.
if you need uinavigationController in second tab then change only secong tab class to uinavigationController
step 3: create new uiviewcontroller. open its xib and add uitableview and segment control to that.
Setp 4: now expand tabbarcontroller and check your second tab have navigationcontroller now add your uiviewcontroller in navigationcontroller's viewcontroller
According to your requirements you can't avoid working with code - I mean that you can't set everything by connections in IB.
I would create a UIViewController (let's call it container) that will contain the segmented control and the navigation controller.
You should set the second tab to be a view controller and point it to the container.
Container's view (XIB if you want) should contain the segmented controller that will be aligned to bottom and a containerView that will fill the rest of the view and will have its IBOutlet.
Container should also have a navigation controller member that will be initiated in viewDidLoad.
The table view that you talk about should also be built in its own XIB and have its own view controller that will be set as root view controller to the navigation controller...
Tell me if it's too confusing / complicated...