I want to push a view from the UITabBarControler. My app hierarchy looks like this:
UINavigationController -> UIView -> UITabBarController
I have a UITabBarController with 3 tabs. On the first tab, I have added a UITableView. How can I make it so that the selection of a cell in the table pushes to another view without navigating from the tab control?
Your problem is the arrange you are doing.
You are using UINavigationController -> UIView -> UITabBarController, so UITabBarController is a subview of the UINavigationController. When you navigate, the view you are popping is FROM THE NAVIGATION CONTROLLER, so ALL its content (including the UITabBarController) will disappear.
You structure needs to be like this:
UITabBarController -> UINavigationController -> UIView, which means one UINavigationController per every tab that needs it.
For example, if you need to use push inside two tabs, the structure should be like this:
UITabBarController
| --> UINavigationController 1 --> UIView 1 --> (push segue) --> UIView 1B
| --> UINavigationController 2 --> UIView 2 --> (push segue) --> UIView 2B
If you really want a navigation-controller type push inside the tab bar interface, you need a navigation interface inside the tab bar interface.
Your simplest solution, though, might be to reconsider your interface.
Like this:
How to handle UINavigationControllers and UITabBarControllers iOS 6.1
That's a more complicated version, but take a look at the Tab Bar Controller and it's relationship with it's contained viewControllers.
Basically you don't want your tabBarController to be embedded in that Nav Controller. Instead, each contained viewController that wants to push on should be embedded in it's own Nav Controller. So in your case you would at least do that for your first tab's tableViewController.
Related
I have 4 main ViewControllers that are connected to a UITabBarController. These are the 4 main screens of my application. Each of these 4 screens has an icon on the TabBar.
Now, from within one of these main screens, I want to be able to click a button to show a new "child" view controller. When I segue from the MainVC to the ChildVC, the UITabBar does not show on the ChildVC. How can I get the UITabBar to remain shown? I do not want to add the ChildVC to the UITabBar, as it should not have an icon on the bar.
I am open to using any type of segue or combination of views.
Within MainVC, I want to click a button to show ChildVC WITHOUT losing the UITTabBar from the MainVC (and without adding ChildVC as an icon to UITabBar).
If I understood your question's hypothesis correctly, you should stack all 4 “main screens” into separate navigation stacks (UINavigationController).
So the outcome would be:
UITabBarController -> UINavigationController -> UIViewController (1 of those main screens) click button -> Desired UIViewController
Have a look at this: https://stackoverflow.com/a/27425271/8290785
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 running project with 2 xibs for 2 UIViewControllers (no storyboard). I am looking for the shortest way to add tabs at the bottom of the screen being able to switch between the views via the tabs.
Thanks,
Simon
SHORT ANSWER:
In your MainWindow add a UITabBarController
In your UITabBarController add UITabBarItems for a UINavigationController
For each of those UINavigationControllers set the RootViewController to be the UIViewControllers that you have already
EDIT: More detailed steps, but not necessarily perfect:
Find out which view is loaded when your app is loaded (depending on your XCode, this may well be MainWindow.xib or its RootViewController)
Edit the thing from #1 (if defined in code, edit in code; if designed through XIB, edit through XIB) so that it is pointing to a UITabBarController (ie mainWindow.rootViewController = tabBarController in code)
Foreach view controller you want to add, add a UINavigationController. If you are using XIB, then just drag new navigation controllers to the tab bar. If you are using code, use tabBarController.viewControllers = #[navController1,navController2,navController3,...]
Foreach of the nav controllers you just created, set its rootViewController to be your ViewController you want to add.
How would I set a UITabBarController with all its individual view controllers as the root view in a split view? IB doesn't seem to let me change the class of the root view controller to anything else…I'm using Xcode 4.
Are you using the split-view based application-option? In that case, it worked for me to just extend : UITabBarController in the RootViewController.h-file. I'm not sure what behaviour you want here, but if you set it up like that, you should get the tabbar with all your views (you have to add them in RootViewController.m ofc) in the "root"-option on the navigation bar.
If you want the DetailView to show the same, you have to add a navigationcontroller to the detailview as well.
As for the "more elegant" solution with IB, I'm afraid I'm not very fond of or very experienced with IB.
You want to add tabbarcontroller to your split view at rootview side and its very simple.
create as many viewcontrollers subclasses with xib for ipad as u want to put in tabbarcontroller.
Then expand your splitview , u have two things navigationcontroller(which in turns contain rootview controller),detailview controller(right side view).
Open your library just drag tabbar controller exectly onto navigationcontroller ,so it will replace all that navigation controller and rootviewcontroller(i assume u dont need that rootview controller or u can create it later).
now expand this tabbar controller u can see viewcontroller 1 - viewcontroller 2 etc.
Now simply select view controller 1 , open attributes and select nib file on [command 1 attribute] and select controller file for that nib file by press[command 4 attribute].
Reapet this for view controller 2 in tabbarcontroller and save close IB.
run program select landscape then u can see its done.
Thanks to dh14-sl and lecou—the solution was a combination of both your answers. I was trying to drag a tab bar controller from the library onto the list of elements but it wasn't working—turns out I had to drag it to the view itself. Then I had to change the parent class of my rootvc and re-setup connections, but now it seems to work! Thanks guys!
I want to have a UIView inside of a NavigationController that has 4 buttons. Clicking on any of these 4 buttons will push a UITabBarController that contains a NavigationController with a respective UIView.
Is this possible? Tweetie seems to do something similar.
On my application, I have a tab bar view controller, then inside of that, I have navigation controllers going to individual views in my interface builder. I believe if you just copy this format, it will work.(-> means connected)
Tab Bar View Controller->4 separate Navigation Controller->ui views
I hope this helps