So, I want my app starts with a UIViewController(without seeing a tabbar), and then enter a UITableView with navigationbar and tabbar. the problem is that the Tabbar is visible at the app starts up, anyone can help on this will be very appreciated...
I think you should either send -presentModalViewController:animated: to your main UIViewController with the tab bar controller as an argument or just do this:
[myWindow addSubview: myTabBarController.view];
Make your app a navigation based application (rather than a tab bar based one) then add a tab bar on the UITableView.
There is help for adding the UITabBar here
I do it like this : in this case drawing a table view and map view (From the Locati application)
tabBarController = [[UITabBarController alloc] init]; // creates your tab bar so you can add everything else to it
searchTableViewController = [[SearchTableViewController alloc] init]; // creates your table view - this should be a UIViewController with a table view in it, or UITableViewController
UINavigationController *searchTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchTableViewController] autorelease];
[searchTableViewController release]; // creates your table view's navigation controller, then adds the view controller you made. Note I then let go of the view controller as the navigation controller now holds onto it
searchMapViewController = [[SearchMapViewController alloc] init];
UINavigationController *mapTableNavController = [[[UINavigationController alloc] initWithRootViewController:searchMapViewController] autorelease];
[searchMapViewController release]; // does exactly the same as the first round, but for your second tab at the bottom of the bar.
tabBarController.viewControllers = [NSArray arrayWithObjects:searchTableNavController, mapTableNavController, nil]; //add both of your navigation controllers to the tab bar. You can put as many controllers on as you like
I found this pattern a long time ago. Sorry that I can't point at the original.
YOu then need to add the tabbarcontoller to the relevant view ([...view addSubView:tabBarController];) possibly setting frame first.
Related
I have developed a tab based iphone application.
In this, I am facing a problem as described below:
The view associated with 1st tab bar contains 2-3 buttons. Action of these buttons are to load another view. Now on pressing these buttons the views are loading but in full size(320x480) and hiding the tab bar.
I want to load that view just above the tab bar so that tab bar is accessible.
I explicitly set the view frame in that view's viewDidLoad function, but it is not working.
Please help me out.
Try this :
You need to start with view based application. And then create a UITabbarController in you appDelegate file.
Appdelegate.h
UITabBarController *tabBarController;
// set properties
Appdelegate.m
// Synthsize
tabBarController = [[UITabBarController alloc] init];
tabBarController.delegate=self;
//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController
Search * search = [[Search alloc] init];
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search];
Nearby* nearby = [[Nearby alloc] init];
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby];
Map* map = [[Map alloc] init];
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map];
AboutUs* aboutUs = [[AboutUs alloc] init];
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs];
Favorites* favorites = [[Favorites alloc] init];
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites];
NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil];
tabBarController.viewControllers = controllers;
[window addSubview:tabBarController.view];
You can accordingly manage in which tab you want to place navigation controller or only a view controller.
Then in each of the view controllers mentioned above you need to implement
- (id)init {}
in which you can set Tab name and image.
Rename the tbs as per your requirement. Place 2 buttons in the one of the views which is Navigation controller.
Hope this helps.
Typical application navigation allows the user to freely move forwards and backwards, between tabs etc. This is facilitated by pushing and popping ViewController's on the navigation bar stack.
In certain scenarios you want to force the user to complete some task and this is when you should use a modal view controller. When the application presents a modal view the idea is that the user should NOT be able to navigate away from the view, instead they should only be able to complete or cancel the action and hence the default behavior for a modal view is to hide the navigation bar, tab bar etc.
It sounds to me from your description that you are performing navigation and not a modal task and thus can I recommend using pushViewController instead of presentModalViewController?
If you are only using presentModalViewController because you want a bottom to top animation then you'll need to use a custom animation.
I have a very simple question. I have a view controller. In the view controller, i have added few buttons. On button click I have to start a tab bar controller (each of which has navigation controller).
Code Snippet:
- (IBAction) pushNewsAlertsController:(id)sender {
//Create a navigation controller
UINavigationController *FirstNavController = [[UINavigationController alloc] init] ;
//create the view controller (table view controller)
FirstViewController *firstViewController = [[FirstViewController alloc] init];
[FirstNavController pushViewController:firstViewController animated:YES];
//Create a navigation controller
UINavigationController *secondNavController = [[UINavigationController alloc] init] ;
//create the view controller (table view controller)
SecondViewController *secondViewController = [[SecondViewController alloc] init];
[secondNavController pushViewController:secondViewController animated:YES];
// Set the array of view controllers
tabBarController.viewControllers = [NSArray arrayWithObjects:firstNavController, secondNavController, nil] ;
//Add the tab bar controller's view to the window
[self.view addSubview:tabBarController.view];
}
I am able to add the tabviews and navigation controller. The problem is I am unable to get back to the main view once the button is clicked.
Can anyone guide me on how to get back to the previous view so that I can click other buttons.
In this case, I would consider presenting the tab bar controller modally. It's a cleaner way of organizing your views in the same way the user interface is organized. You can just dismiss the modal presentation to go back to the previous view. Read View Controller Programming Guide for iOS about similar advice and examples.
Not sure if I get what you are trying to do, but if you want the tab bar controller view to disappear again, the only way would be the inverse of
[self.view addSubview:tabBarController.view];
which could be
[tabBarController.view removeFromSuperview];
I must say it looks like an odd construction you're building, but it may work nevertheless.
my application needs the design similar to sybase ipad app which is here YouTube - Sybase Mobile Sales for SAP CRM on iPad
How can I set a tabbarcontroller as rootview controller of UISplitViewController.
When I try to do this, 8 tabitems are displaying without "More" button. so its overlapping items title. And it will display More button if more than 8 tab items.
As it is using width 320, How to set only 5 tabs visible at a time.
sample
array = [[NSMutableArray alloc] init ];
for(int i=0; i <10; i++){
TestTabController *cc = [[TestTabController alloc]init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:cc] ;
[cc release];
[array addObject:navController];
[alertNavController release];
}
mytabBarController = [[UITabBarController alloc] init];
mytabBarController.viewControllers = array;
splitViewConntroller = [[UISplitViewController alloc] init];
[splitViewConntroller setViewControllers:[NSArray arrayWithObjects:mytabBarController, detailNavigationController, nil]];
How can I set the detailController view as a controller in the tabbarcontrolller(rootController) at runtime -Any easy methods ?-.. We can see when user tap on a cell in the detailController view, it immediatly move to rootController and its detail will show in detailController
Any help/comments/suggestions would be grealy appreciated.
If you create a UISplitViewController based project from the project templates and then open the MainWindow.xib file in interface builder, you can then just drag a tab bar controller component from the Library palette onto the first view controller (the navigation controller) inside the split view controller. Then you should be able to just start adding view controllers to the new tab bar controller. You then just specify the view controllers you want to use for each of the tabs. I've created several projects this way and it works quite well.
Of course, I'm assuming Xcode 3 here. I'm not completely sure if it's the same in Xcode 4 if that's what you're using.
if I'm not mistaken, UITabBarController should always be the root view controller in all cases.
So you're going the opposite way.
I'm creating an application that, when the user selects a project in a table, displays a view with a tab bar at the bottom. I'm using this code:
- (id)init
{
[super initWithNibName:nil bundle:nil];
tabController = [[UITabBarController alloc] init];
// Create all view controllers to be included in the tab bar
SummaryViewController *summaryController = [[SummaryViewController alloc] init];
ImagesViewController *imagesController = [[ImagesViewController alloc] init];
// Make an array containing the view controllers
NSArray *viewControllers = [NSArray arrayWithObjects:summaryController, imagesController, nil];
[summaryController release];
[imagesController release];
// Attach them to the tab bar controller
[tabController setViewControllers:viewControllers];
[self.view addSubview:tabController.view];
return self;
}
With the end result being the tab bar at the bottom appearing cut off around half its height. I'm guessing it's somehow related to the navigation controller at the top (link to image).
Any help in solving this mystery would be greatly appreciated!
I believe the problem here is that you're adding the UITabBarController as a subview of another UIViewController. UITabBarController descends directly from UIViewController.
Instead of creating this view controller to hold it, you should just create the tab bar controller, configure it and push that onto your stack.
I want to customize the look and feel of the tab bar of a UITabBarController. I want to change the colors, the way the icon looks when they are selected, and also, most important of all, I want to reduce the size of the custom toolbar.
My approaches for this and the hurdles in it are:
A) The first solution which came to my mind was to create my own viewController which will act like a UITabBarController with buttons in the bottom and add this viewController to the window. Once when user taps a button at the bottom, swap the view in the viewable area with the new viewController's which corresponds to the button now tapped by user.
The problem with this strategy is: since I swap view's the corresponding viewControllers will not get these messages:
viewWillAppear
viewWillDisappear
viewDidAppear
viewDidDisappear
And all the rotation events
B) I could have used the accepted answer's approach in this thread:
Custom UITabBarController Problems with View Controllers and Views
But my tabBar's height is not the same as the default.
Due to the cited reasons above, I cannot use those approaches.
Having said this, I have no special requirement of More tab. I will be having only 5 tabs which will be displayed by the tab bar and hence the re-ordering of tab bar items is out of scope.
Awaiting suggestions and ideas.
I have never attempted something like this but as I see it, you are supposed to send those messages to your child view controllers manually.
It shouldn't be problem to send -viewWill/Did(Dis)Appear to the right controller at the appropriate moment. This is what UITabBarController does, too.
As for rotation events:
In shouldAutorotateToInterfaceOrientation:, forward this message to your child controllers and set your return value depending on their return values (UITabBarController only returns YES if all its child controllers return YES for the requested orientation).
Forward willRotateToInterfaceOrientation:duration:, didRotateFromInterfaceOrientation: and willAnimateRotationToInterfaceOrientation:duration: to the child controllers (at least to the currently visible one) when you receive them.
If you have set the autoresizing masks of your child controllers' views correctly, they you rotate and resize correctly when the system rotates your custom tab bar controller's view. (At least I think that's how it should work.)
Again, I'm not sure if this will work.
You can implement the following code for the creating the custom tab bar in that use to images using the CGRect make.further code is use for the creating the custom tab bar
-(void)applicationDidFinishLaunching:(UIApplication *)application {
// Add the tab bar controller's current view as a subview of the window
tabBarController.delegate = self;
tabBarController = [[UITabBarController alloc] init];
mainDashBoard = [[DashBoard alloc] initWithNibName:#"DashBoard" bundle:nil];
mainSearchView = [[SearchView alloc] initWithNibName:#"SearchView" bundle:nil];
mainMoreView = [[MoreView alloc] initWithNibName:#"MoreView" bundle:nil];
UINavigationController *nvCtr0 = [[[UINavigationController alloc] init] autorelease];
UINavigationController *nvCtr1 = [[[UINavigationController alloc] initWithRootViewController:mainDashBoard] autorelease];
UINavigationController *nvCtr2 = [[[UINavigationController alloc] initWithRootViewController:mainSearchView] autorelease];
UINavigationController *nvCtr3 = [[[UINavigationController alloc] initWithRootViewController:mainMoreView] autorelease];
UINavigationController *nvCtr4 = [[[UINavigationController alloc] init] autorelease];//[[[UINavigationController alloc] initWithRootViewController:nil] autorelease];
tabBarController.viewControllers = [NSArray arrayWithObjects:nvCtr0,nvCtr1,nvCtr2,nvCtr3,nvCtr4,nil];
nvCtr0.tabBarItem.enabled = NO;
nvCtr4.tabBarItem.enabled = NO;
[window tabBarController.view];
}