I have a UITabBarController. Now I want to add a view above it, and make the view unchanged when users switch to another tab. I've tried to create a UIViewController, and add the UITabBarController as a subview, but it crashed when I switched to another tab.
Is there any good way to do it? Thanks for any help.
Sure there is. What you'll want to do is make a view controller, which will house the view that is constantly visible, and add the tab bar controller on top of it. If you're using storyboards, this can be accomplished easily using a container view. Simply drag and drop a container from the object library onto the view controller you created, size it as you wish, and link its viewDidLoad segue to embed on the tab bar controller.
http://dl.dropbox.com/u/91385349/tabInView.zip
Related
I have a viewcontroller and a tab bar controller. I want to change view controller as initial view controller and create a segue to show tab bar controller.
I have tried to set the new initial view controller. There are 2 ways. First, check the tick box "Is Initial View Controller". Second, drag the arrow to new screen. It does not show any error, but it shows the tab bar controller as usual and I can't find the view controller either.
Anyone know how to what is going on. Please tell me to fix. Thanks
You need to use a UINavigationViewController and connect it up in the hierarchy in a similar fashion to:
The leftmost view is the "view" that you mention, which needs to show the UITabViewController.
I've added a button for ease of use.
The next along (send from the left) is the UINavigationViewController. No settings on here need to be set etc... it's pretty much "plug and play" as to put it.
The next view (third from the left) is the UITabViewController (with corresponding views to it's immediate right).
The connection between the UINavigationViewController and the UITabViewController is "rootViewController" as the Tab View is the "root view controller" e.g. the primary view controller.
The segue between the first view, and the navigation view controller is merely a "show" segue. I liked directly between the button and the navigation controller in Xcode.
Hope this mash-up helps!
Edit I wrote a quick mask up of what I posted in the images for you to play with: https://dl.dropboxusercontent.com/u/61211034/Stackoverflow/NavgationViewController.zip
Based on your storyboard's image, looks like you don't have any NavigationController embedded to your root LoginViewController, try this:
Select your LoginViewController on your storyboard
Then in xcode Menu bar at the top, go to Editor -> Embed in -> Navigation Controller (as you can see in the image below)
Then your NavigationController will be set as your Initial View Controller, and see your LoginViewController be displayed and work as expected your segue.
I created a Single View application with a view controller that allows you to enter homework assignment data. I now am trying to add onto this app by creating a navigation controller. I want the First Screen to be a Table View, that switches to the homework assignment screen when you click the "Add" arrow.
I've created the Navigation controller onto the Table view, and connected the Add button to the Assignment View Controller, but when I start the app, it still opens up to the Homework Assignment screen.
Can anyone provide a simple way to change the startup screen to my TableView?
EDIT: I am using storyboard. I havent added/edited any new code anywhere for the Table view/ Navigation controller/AppDelegate, I just dragged and connected with storyBoard, I just need to app to startup on the table View instead of the Homework assignment View Controller.
In your storyboard, select the view controller that should be the initial one. Go to the utilities view (on the right). Open the attributes inspector. Tick the Is Initial View Controller checkbox.
I'm creating an UIViewController in IB. And I want to use this controller with a UINaviagationController.
The problem is when I use this view controller with the navigation one the title bar appears and all the elements on view go down. Ho can I take account of this when creating the controller in IB ?
PS: Now, I just put everything a bit higher. But I don't think it's a right way.
In IB select the view controller view, open the inspector, select the View Attributes tab, and on Top Bar specify "Navigation Bar". This will make a Navigation Bar in the view and then you'll be able to place your subviews in the remaining content.
In the same way you can inform IB if your view will contain the status bar, the tab bar, a prompt.
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...
I have setup a tab bar application with four tabs on the bottom (as set inside IB) Three of them are UIViews and one of them is a UITableView, and the empty shell of an app switches between tabs fine.
Now, being that I have no experience with tab bars, I am not sure where my logic for the view controllers goes. I am used to setting up a ViewController for each view, is that the case in a tab bar? Does each tab need a separately programmed viewcontroller? If not, how can I link my logic to the correct tab's view?
Please help. Thanks!
A UITabBarController manages an array of UIViewController objects. These in turn manage the UIViews that are visible to the user.
So yes, you need to create a separate UIViewController for each view that you want the UITabBarController to manage.