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
Related
I really need help on creating a UIWebView on a Tab Bar Controller. But I Bumped into a road block.
Basically I started out with the Tab Bar Application Template, then;
Removed the First and Second Controller XIB files on the resource folder (since it's not really needed
In Interface Builder, I removed default contents in the First and Second View Controller and added a View first, then a Web View after that on both the View Controller
After that, I started coding on both on the First and Second View Controller headers with just this code:
#interface FirstViewController : UIViewController { IBOutlet UIWebView *twitter; }
(also for the Second View Controller's header)
Then I linked the Outlets to the UIWebView and linked both Tab Bar Item to their Class View Controller (First Tab Bar Item linked to the FirstViewController class, then for the second one as well)
Later in both the View Controller's .m files, I added
- (void)awakeFromNib
{
[twitter loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:#"twitter.com"]]];
}
(and for the other one)
Now when I compiled the application, it gave me:
'First View Controller (First)' has both its 'View' and 'NIB Name' properties set. This configuration is not supported.
I looked through every youtube video about this topic, but none of their comments even mentioned anything about this kind of error, I hope someone can explain how to get through this error, thanks
In Interface Builder you can either define a view in your MainWindow.xib directly inside the TabBarController, or you can tell Interface Builder that those views are loaded from separate XIB files.
It sounds to me like you are defining the views directly inside your main XIB, so in that case you need to select the view controllers that are in the TabBarController, hit Apple-1 to open the attributes pane for the controller, and clear the "NIB name" field which is probably still set to "FirstViewController". Do the same for any other view controllers you have in your TabBarController.
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 a tabBarController xib. I've set the first item's class to a view controller I made (.h and .m files, no .xib). When I try to push the tabBarController, I get a warning saying the tabBarController "view outlet was not set".
I'm not sure how to set the view outlet, since I am loading from another view. I'm expecting the default grey view with detailed edges will load from my ViewController.h file because I set the class there, but instead I'm crashing with that error.
Suggestions?
Normally, you would add view controllers to the tab bar controller in the xib. They need to have a view linked up, which you can also do in IB.
If you want to do that programmatically, you should, after loading the xib, but before showing the vc, take the elements of
NSArray *vcs = [tbCtrl viewControllers];
walk through them, and set their view property to a view. When pushed, the tab bar controller will know which view to load: namely the view of the first tab. These things are really much easier to handle in IB.
Is there a good UITabBarController example where it is NOT created in the appDelegate?
I would like to use a UITabBarController inside of a UIViewController, however dont know how to set the view outlet.
This is all very well documented here. It shouldn't matter where the UITabBarController instance is created, UIApplicationDelegate or not. In a nutshell, Create all of your respective UIViewController's and add them to an array. Then assign that array to your UITabBarController's viewControllers property. Then you can simply do something like [window addSubview:myTabBarController.view].
I'm just copy/pasting from the documentation here:
You should never access the tab bar
view of a tab bar controller directly.
To configure the tabs of a tab bar
controller, you assign the view
controllers that provide the root view
for each tab to the viewControllers
property. The order in which you
specify the view controllers
determines the order in which they
appear in the tab bar. When setting
this property, you should also assign
a value to the selectedViewController
property to indicate which view
controller is selected initially. (You
can also select view controllers by
array index using the selectedIndex
property.) When you embed the tab bar
controller’s view (obtained using the
inherited view property) in your
application window, the tab bar
controller automatically selects that
view controller and displays its
contents, resizing them as needed to
fit the tab bar interface.
Here's one implementation of UITabBarController initialized in a UIViewController.
The author also posted a github link to the xcode project.
Here goes stupid question again :(
I am trying to create a sample app that loads UIViewController when the app loads and the view contains a button to load UINavigationViewController.
Now I created a project with "Window-based Application" and added "RootViewController" in the project with .m, .h, and .xib.
Next I added a view and a button in the "RootViewController.xib" file and it runs ok. After that, I added "UIViewController subclass" file naming "NavViewController" with .h, .m and .xib files.
Also I added - (IBAction)buttonPressed:(id)sender function in the "RootViewController" classes to load NavigationViewController.
Here is the code of the "buttonPressed:".
- (IBAction)buttonPressed:(id)sender {
NavViewController *navViewController = [[NavViewController alloc] initWithNibName:#"NavViewController" bundle:nil];
self.navController = navViewController;
[self.view insertSubview:navViewController.view atIndex:0];
[navViewController release];
}
When I "build and go," it runs fine initially until I press the button. When I press button, program terminates it.
What am I doing wrong? Please help...
Thank you.
What are you doing wrong? Designing your app in a non-standard way - you are not supposed to be able to do this - the NavigationController is in charge!
Why would you have a button that then adds a navigation controller? - it goes against the user interface guidelines. I found it hard to get to grips with the interface guidelines to begin with but you really must because it will make your app so much more usable.
If you need a navigation controller then add it to the view to begin with - or create a new view with the navigation controller. Honestly try it out and you will feel the user interface feels much better.
If you really want a button that adds a navigation controller to the window then do the following:
Keep a reference to the AppDelegate in your code
Use this reference and pass in your current view controller to a method called reloadMainViewWithNavBar:(UNViewController*) viewController
This new method should remove the old mainViewController and create a NavigationController
using your viewController as the root view conroller
add the navigation controller view to window view
The navController has no view set in the nib. A UINavigationcontroller needs a root view. In the nib, connect the navigation controller to a another view controller.
In addition to the fix mentioned above, what you really want to do is create the first view controller contained in the navigation controller - but hide the navigation bar until the button press causes it to unhide. You cannot easily add a navigation controller to a view you are in.