uinavigation bar in all view - iphone

In my project the navigation bar is being coming only in rootview(homeview) for the first only,i want to enable navigation bar in all views?Here my code?What change should i do for that
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.window.rootViewController =navigationController;
[self.window addSubview:[navigationController view]];
[self.window makeKeyAndVisible];
return YES;
}
Please help me to code?

See this link
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
navigationController =[[UINavigationController alloc] init];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[navigationController pushViewController:viewController2 animated:NO];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
}
And when you navigate to the another view from viewController2 do pushViewController not others like presentView
[self.navigationController pushViewController:anotherViewController animated:YES];

Put this code in a delegate class.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Set the navigation controller as the window's root view controller and display.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}

If you want to enable navigation in all the views then you will have to declare the navigation in AppDelegate.m wherein it will be viewable in all the views. I dont have my mac rite now but its the best advice I can provide for now :)

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:viewController2];
self.window.rootViewController =navigationController;
[self.window addSubview:[navigationController view]];
[self.window makeKeyAndVisible];
return YES;
}
Change the uiviewcontroller to SecondViewController

try this way may be helped you
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// [NSThread sleepForTimeInterval:0.1]; // simulate waiting for server response
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
// Initialise the navigation controller with the first view controller as its root view controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
// This is where we hide the navigation bar! :)
[navigationController setNavigationBarHidden:NO];
// Navigation controller has copy of view controller, so release our copy
//[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
[self.viewController release];
// Add the navigation controller as a subview of our window
[_window addSubview:[navigationController view]];
[_window makeKeyAndVisible];
return YES;
}

Related

implementation of tab bar programmatically not in the rootView

I asked the same question before for the some but now i changed the way to implement my tab bar i have this view
i want when i push a button it will make a tab bar composed in 5 buttons the some that i can choose it in the first view
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
AcceuilViewController *viewController =[[[AcceuilViewController alloc]
initWithNibName:#"AcceuilViewController" bundle:nil]autorelease];
self.navController = [[[UINavigationController alloc]initWithRootViewController:viewController]
autorelease];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
}
Create your UITabBarController as per normal. When a user touches a button, push to that controller:
YourTabController *tabController = [[YourTabController alloc] initWithNibName:#"Tabs" bundle:nil];
[self.navController pushViewController:tabController animated:YES];

can't navigate to another ViewController

I'm newbie. There is a button in ViewController.m . When I press the button it has to navigate to SecondViewController but SecondViewController doesn't appear.
And at the SecondViewController on the navigation bar, there will be "Back" button to go back to ViewController. Can you tell me what I'm missing?
ViewController.m:
-(IBAction)buttonPressed:(id)sender
{
EnglishViewController *v = [[[EnglishViewController alloc]
initWithNibName:#"EnglishViewController"
bundle:nil]
autorelease];
[self.navigationController pushViewController:v animated:TRUE];
}
AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
The solution (depends on #George's answer):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
UINavigationController *navCon =[[[UINavigationController alloc]
initWithRootViewController:self.viewController]
autorelease];
self.window.rootViewController =navCon;
[self.window makeKeyAndVisible];
return YES;
}
When you create your ViewController in AppDelegate.m you must surrond it with navigationController to make it work
Something like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.viewController = [[[ViewController alloc] initWithNibName:#"ViewController" bundle:nil] autorelease];
UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:self.viewController];
self.window.rootViewController = navigation;
[navigation release];
[self.window makeKeyAndVisible];
return YES;
}
The first few things to check: is your -buttonPressed method actually getting called? Is are you getting and passing a non-nil value to -pushViewController:animated:? Is self.navigationController actually non-nil when you make that call?
Your code looks fine as written.

How to add navigation controller in landscape ios6

While am trying to add navigation controller in landscape based app ios6 application it shows in Portrait Mode only like in the image,What change should i made?
In app delegate file coding,
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
[self.window addSubview:[navigationController view]];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
Check this to add UINavigationController in your app :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// start of your application:didFinishLaunchingWithOptions
// ...
viewController = [[ViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:viewController];
[self.window setRootViewController:navigationController];
[window makeKeyAndVisible];
[viewController release];
[navigationController release];
return YES;
}

Hiding the UINavigationController on the first .xib file only

This may be a stupid question but I programmatically added a UINavigationController to my app. If possible, I wanted to just add it to the top of all my windows except for the very first .xib. Maybe even just hide it on my first .xib. Is it possible to even do that? I think of my first .xib file that opens up to the rest of my app like a cover page and I rather that blue bar not show up at the top of that. I wish I could show you pictures but don't have enough reps yet. Thanks!
Below is the code I believe helps me to provide each page of app with the back bar:
#import "McCormick_TaylorViewController.h"
#implementation McCormick_TaylorAppDelegate
#synthesize window = _window;
#synthesize viewController = _viewController;
- (void)dealloc
{
[_window release];
[_viewController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
autorelease];
// Override point for customization after application launch.
self.viewController = [[[McCormick_TaylorViewController alloc]
initWithNibName:#"McCormick_TaylorViewController" bundle:nil] autorelease];
UINavigationController * navController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}
in your McCormick_TaylorViewController's viewWillApper: method
just use bellow code...
[self.navigationController setNavigationBarHidden:NO animated:YES];
and in other view controller in navigationbar ot display then in another viewController's viewWillAppear just use bellow code..
[self.navigationController setNavigationBarHidden:NO animated:NO];
Use this method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
autorelease];
// Override point for customization after application launch.
self.viewController = [[[McCormick_TaylorViewController alloc]
initWithNibName:#"McCormick_TaylorViewController" bundle:nil] autorelease];
UINavigationController * navController = [[UINavigationController alloc]
initWithRootViewController:self.viewController];
[navController.navigationBar setHiden:YES]; // hides navigation bar
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}

set class for UINavigationController

How to set class(first class) for UINavigationController from code ?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
LoginViewController* loginViewctrl = [[LoginViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:loginViewctrl];
UIWindow* window addSubview:[navigationController view]];
[loginViewctrl release];
[window makeKeyAndVisible];
}