Changing UIViewController tab bar view to UINavigationController in Xcode 4 - iphone

I am trying to modify a newly placed UITabBarItem item from a UIViewController to a UINavigationController in XCode 4.
Here is a screenshot of a new view controller called "Near Me" and existing view controllers.
Notice how the new one is a UIViewController, I need this changed to a UINavigationController.
Something as simple as this was easily done in Xcode 3.2 and now that Apple has introduced Xcode 4 - it is just horribly difficult to re-learn this new IDE.

You shouldn't modify a UIViewController to be a UINavigationController. Even though a UINavigationController is a subclass of UIViewController, its job is to manage other View Controllers, not Views.
In IB you should create a UINavigationController and then set the existing UIViewController as the root controller of the new UINavigationController.

You can change it in the menu on the right hand side. Just change the class. I hope this is what you are asking for.

First you create window based application an in that MainWindow.xib file put tabBar Controller. Then delete that two UIView controller and add navigation controller under tabBar Controller. You can see below in screen shot.

Related

add tabs to existing project

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.

Converting an Utility application (2 view controllers) to a Tab bar Application

As the title suggests, I have built an utility based app.
The app consists (at the moment) of 2 view controllers + a model class hierarchy.
The thing is , as I'd like to add some features to the app , I would like to convert it to a TabBar based application.
As a first step , I would like the first view to be the first view of the tab bar , and the flipSideView to be one of the other tab bar items.
Is there any "standard procedure" / "grocery list" for such tasks ?
I'm sure some of you have encountered the same problem , and would love some advice on "slicing up" the app , and "wiring it up" after creating a new nib file for the main window (is that the first step ? )
Thanks in advance.
I would probably start as follows (assuming you are using Interface Builder and using the standard Xcode utility app template):
Edit your MainWindow.xib file and drag a Tab Bar Controller object into the top level of your view hierarchy.
The default tab bar controller in IB includes two view controller items as examples. Click the first one and change its class to be your existing Main View Controller class.
You can also set the icon and tab bar title for the main view controller item by adding the associated Tab Bar Item that IB has already added to the view hierarchy.
Do the same for the second tab bar item setting the class for the FlipsideViewController.
Delete the old version of your Main View Controller from the NIB file and also remove the IBOutlet property from the Application Delegate (you probably also have references to the main view controller in dealloc which should be removed).
In your App Delegate add an IBOutlet property for the Tab Bar Controller as follows (don't forget to synthesise the property):
#property (nonatomic,retain) IBOutlet UITabBarController *tabBarController;
In IB wire up the tabBarController outlet from the App delegate object to the Tab Bar Controller object.
Finally to get the tab bar controller to show up in place of the main view controller change the code in application:didFinishLaunchingWithOptions: to the following:
[self.window addSubview:self.tabBarController.view];
This should get the basic tab bar app up and running and you can add additional view controllers to the tab bar.
Since you no longer want to flip between the MainView and FlipsideView you can remove the references to the FlipsideViewControllerDelegate from the MainViewController along with the info button and its IBAction method showInfo. Likewise in the FlipeSideViewController you should remove the done button from the view and its IBAction method as these no longer make sense when used with the tab bar.
so, step by step :):
1. declare UITabController outlet in your app delegate.
2. in MainWindow.xib: first drag the instance of UITabBarController in document window, then make connection from app delegate to that instance. now you can set MainViewController as UiTabBarController's first tab viewcontroller, then set FlipsideViewController as UiTabBarController's second tab viewcontroller.
3. in app delegate's appDidFinishLaunching replace [self.window addSubview:mainViewController.view]; with [self.window addSubview:theNameOfUITabBarControllerOutlet.view];. that will do the work. sorry, I don't know your background, that's why I'm not very specific about performing a particular action I decribe, so let me know if you find yourself stuck

Adding Tab Bar Controller to Root View of UISplitViewController?

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!

How to properly use a UITabBarController in Monotouch

I understand what to do when using a UITabBarController with the MainWindow. But if when I'm in IB and I decide I want to have a UITabBarController, I only ever get a UIViewController that has a UITabBarController. If this is how it needs to be, then when do I .AddSubView of the UITabBarController? In the ViewWillLoad of the UIViewController? Do I just change the class that is inherited from in the code?
Bit lost here.
This is what I do:
derive from UITabBarController in IB
add the new class to my XIB
(if I want to add new tabs outside of IB, I override LoadView in my tab bar controller class and do it in there)
in AppDelegate.FinishedLaunching, I add my tab bar's view as a subview of 'window' (ie window.AddSubview(mainTabBar.View); )
Those steps work for me without any obvious problems.

iphone - transforming a view-based project

sorry bothering you guys with this silly question, but I am a kind of noob in iphone development. What I need to do is this. I have a project developed by a friend of mine, that is view-based. He created it based on the original apple template on Xcode.
After banging my head on the wall, I realized that I need to transform this project from view based to UINavigation based project. What I mean is: his project has one view controller and one delegate. When it runs, the delegate calls the view controler and the equivalent view loads.
What I need is to insert a UINavigationController before the ViewController, because I am planning to have a second ViewController managed by this UINavigationController, so I can do slide transitions between them and things like that.
My question is: I imagine this is not a complex operation if you want where to change. Which changes and where should I do them, in order to add a UINavigationController before the viewController? I imagine this will change the hierarchy to:
Delegate > UINavigagionController > ViewController
Remember that this project was based on the Xcode View-based template, so I will probably have to change stuff on Interface Builder.
Thanks.
In IB, add a UINavigationController to your MainWindow.xib.
Drag the existing view controller onto the nav controller icon to make it the nav controller's root controller.
In your code, add a property to your application delegate for the navigation controller. Mark it as IBOutlet.
In IB, connect the navigation controller object to the navigation controller outlet in your app delegate.
In your code, in -application:didFinishLaunchingWithOptions:, change the references to your original view controller to the new navigation controller property.