in ios app i want to implement "navigation-bar" and "side-bar" both in a single app like below image
for the tabbar controller i have to assign as a rootviewcontroller
and for sidebar controller also have to assign as a rootviewcontroller.
[self.window addSubview:[tabBarController view]];
and
MenuViewController *menuViewController = [[MenuViewController alloc] initWithNibName:#"MenuViewController" bundle:nil];
self.window.rootViewController = menuViewController;
how two different tab-bar assigned as rootviewcontroller, any idea.. thanks in advance
Related
I have a working application with a UITableViewController as a root view controller.
I need to pop a simple log-in screen on app launch,
and i can't set it as root view controller because it's against the project properties.
also, im using storyboard.
Simply, in root view controller (UITableViewController in your case) viewDidAppear's method, present log-in screen as modalViewController. You need to set the Identifier for your ViewController first.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard"
bundle:nil];
LoginViewController *lgn = [storyboard instantiateViewControllerWithIdentifier:#"LoginView"];
[self presentViewController:lgn animated:YES completion:NULL];
Use your own storyboard and viewController names.
In App Delegate
loginViewController = [[BANLoginViewController alloc] initWithNibName:#"BANLoginViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
[window addSubView:[navController view]];
[window makeKeyAndVisible];
And in the BANLoginViewController you could check if the user is logged in or not and then initialise the main storyboard.
Before:
My App is based on indepent view controllers. I can switch from one to another by replacing the root view controller on the application delegate:
ade.window.rootViewController = newController;
... and all worked right, till now.
Tomorrow:
we have to add a NavigationController-based part of our App, which will help the users navigate through our:
Brands => Model Names => Colors
So, the user will choose a color, then click a button: now I will switch to another UIViewController (call it "pippo"), which actually resides outside that navigation hierarchy (I can't push it in the nav-controller for several methods, I'm forced doing so!).
What I want is to get back to my "Color" screen, from "pippo". So, I'm looking for a way to programmatically "navigate" the navigation controller I restore, I mean:
I restore my navigation controller
now I'm on Brands, but I don't want my users to be here, I want to show them the last color they was on (I saved it in the preferences)
how can I simulate the selection of a known brand and model?
Thanks a lot.
In applicationDidFinishLoading in App delegate:
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
[window makeKeyAndVisible];
[window addSubview:navController.view];
That will instantiate the navigation controller and add it to the window as a view.
Now, in your rootViewController class (lets say its called FirstViewController) you can do this:
- (void)clickedAButton:(id)selector {
SecondViewController *nextViewController = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
// and push it onto the 'navigation stack'
[self.navigationController pushNavigationController:nextViewController animated:YES];
// and release
[nextViewController release];
}
And in your SecondViewController you can navigate back through the stack using:
- (void)clickedAnotherButton:(id)selector {
// goes back to the last view controller in the stack
[self.navigationController popViewControllerAnimated:YES];
}
So for you it would go:
Set up navigation controller in the app delegate with Brand as the root view controller
User chooses their brand and you pushViewController:animated: the Model view controller. Then the user chooses their model and you pushViewController:animated: the Color view controller. Similarly the user chooses a color and you push the Pippo view controller. Now, if the user presses back (or you call popViewControllerAnimated:) it will go back to the Color view controller in the same state as when the user left it to go to the Pippo controller.
Write the following code in AppDelegate.m Class
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
MainViewController *mainViewController = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
self.nav = [[UINavigationController alloc] initWithRootViewController:mainViewController];
self.nav.navigationBarHidden = YES;
[mainViewController release];
[_window addSubview:nav.view];
[_window makeKeyAndVisible];
}
I have created a view based application and in the appdelegate .h file I have created UINavigationcontroller object and added it to window subview. Next in the app did finish launching I had allocated and initialised a class that I want to be viewed when the app first launches with the navigation bar on the top of it.
So this is the code I have did to add the class to navigation bar
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the view controller's view to the window and display.
[window addSubview:navController.view];
//test is the class that i want to be viewed first when the app launches first
test *t = [[test alloc]initWithNibName:#"test" bundle:nil];
[navController.view addSubview:t.view];
[window makeKeyAndVisible];
return YES;
}
but the problem is my test class launches but it does not display the navigation bar. What may be the problem?
Use some like this (add these lines)
appDelegate.h
UINavigationController *navController
#property (nonatomic,retain) UINavigationController *navController;
and in .m
test *t = [[test alloc]initWithNibName:#"test" bundle:nil];
self.navController=[[[UINavigationController alloc] initWithRootViewController:t] autorelease];
[window addSubview:self.navController.view];
[window makeKeyAndVisible];
it helps you.
From other view you need to make object of the appDelegate class then access the navigation controller of that class
see this
yourAppDelegateClass *objAppDelegate=(yourAppDelegateClass *)[[UIApplication sharedApplication] delegate];
now for pushing a view
SecondView *s=[[[SecondView alloc] initWithNibName:#"yournibName" bundle:nil] autorelease];
[objAppDelegate.navController pushViewController:s animated:YES];
this concept help you.
You shouldn't add your own view controller's view as a subview of the navigation controller. This way, you hide the navigation controller's view (including the navigation bar) and it makes the navigation controller pointless, because it doesn't know that your view controller wants to be part of its navigation stack.
Instead, push it on the navigation controller's stack by using:
[navController pushViewController:myViewController animated:NO];
Navigation bar is not coming because you are setting navigation controller's view to your test view. You can do it by setting navigation controller's view controllers which requires an array as -
test *t = [[test alloc]initWithNibName:#"test" bundle:nil];
NSArray *viewControllers = [[NSArray alloc] initWithObjects:t,nil];
[self.navigationController setViewControllers:viewControllers];
First, I don't see where you alloc init your navController. Secondly, you don't add a viewController to a navigation controllers view, rather you push the view controller onto the stack, like this:
[navController pushViewController:t animated:NO];
Hope this helps.
I'm having trouble initializing a viewcontroller when the app loads in my app delegate. The viewcontroller loads okay, but it overlaps the tabbar that I have at the bottom. Do I need to create another viewcontroller and have it load into that in the app delegate? I currently have a tabBarController set up in my MainWindow.xib, which contains Navigation controllers and inside those are viewControllers.
Here is my code...
In my didFinishLaunchingWithOptions I have:
sub = [[SubGabViewController alloc] initWithNibName:#"SubGabViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:sub];
[window addSubview:nav.view];
Should it be something like?
sub = [[SubGabViewController alloc] initWithNibName:#"SubGabViewController" bundle:nil];
nav = [[UINavigationController alloc] initWithRootViewController:sub];
[newViewController.view addSubview:nav.view];
Thanks!
If you're trying to use a UITabBarController, each tab has its own root view controller (these can even be UINavigationController objects). Assuming you have a property for self.tabBarController (I think this gets created by default in Xcode if you are doing a tab-bar app), then:
sub = [[SubGabViewController alloc] initWithNibName:#"SubGabViewContrller" bundle:nil];
nav = [[UINavigationContoller alloc] initWithRootViewController:sub];
[self.tabBarController setViewControllers:[NSArray arrayWithObject:nav] animated:NO];
self.window.rootViewController = self.tabBarController;
// Clean up memory here... only if you don't need references to them
[sub release];
[nav release];
With setViewControllers:animated: you should probably include additional view controllers in the NSArray, otherwise you'll end up with a tab bar only containing one item!
[window addSubview:tabBarController.view]; would be right......
Rather than adding navigation controller using code..... you should add it from Interface Builder.... in interface builder remove the tabBarItem and add a navigationController on it and then set viewController for that navigation controller..........
create an outlet of tabBarController in appDelegate so that you can add it on window. Pleas do not forget to make connection between components in Interface Builder.
Thanks,
my application have a tabbarcontroller with 4 view Controllers.
Its called here :
self.window.rootViewController = tabBarController;
The view controller that appear first in the tabbar is called "Home"
I want when opening the app to load the viewcontroller and not just the tabbar. It is possible? I want the ViewDidLoad() method from my Home view controller to be called. Thanks
If your application is based on a TabBarController, you want to load the viewControllers into your TabBarController and then add the TabBarControllers view to the window. For example:
FirstViewController *fvc = [[FirstViewController alloc] init];
SecondViewController *svc = [[SecondViewController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:fvc,svc,nil];
[window addSubview:tabBarController.view];
[fvc release];
[svc release];
where tabBarController is an instance variable and property. The first tab to display when your app launches will be the first one you load into the array. In this case it is fvc.
Hope this helps.
Just go as usual load the first viewController (use it as Home page )and handle the tabbar hidden property (where you want to show or hide it).