I am new to iOS. And I want to use navigation controller in my application but I have no any idea how to do it. So can any one guide me step by step for creating navigation in my application.
-
have u used in stroyborad or xib in your xcode – Anbu.Karthik Apr 10 '14 at 08:05
-
[Navigation controller Programetically](http://www.idev101.com/learn/navigation_controllers.html) [Navigation controller in storyboard](http://www.appcoda.com/use-storyboards-to-build-navigation-controller-and-table-view/) – Mayank Jain Apr 10 '14 at 07:42
7 Answers
In appDelegate.h
@property (strong, nonatomic) UINavigationController *navController;
and set the delegate UINavigationControllerDelegate
and synthesise object in appDelegate.m
now,
appDelegate.m
you can set navigation controller in didFinishLaunchingWithOptions
method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
frstVwCntlr = [[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.frstVwCntlr];
self.window.rootViewController = self.navController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
In the above code , your firstViewController is set to UINavigationController
and UINavigationController
added to UIWindow
like
self.window.rootViewController = self.navController
Hope this may help you
You can creat UINavigationController in Appdelegate and set your first viewcontroller on it.

- 223
- 2
- 5
So for creating a UINavigationController programatically without using storyboards, go to your app delegate and do the following. Create two properties, window and viewController
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor=[UIColor clearColor];
self.viewController = [[YourFirstViewController alloc] initWithNibName:@"YourFirstViewController" bundle:nil];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
// Override point for customization after application launch.
return YES;
}

- 10,998
- 6
- 50
- 93
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
ImageViewController2 *dealVC = (ImageViewController2 *)[storyboard instantiateViewControllerWithIdentifier:@"ImageViewController2"];
[self.navigationController pushViewController:dealVC animated:YES];
where ImageViewController2 is a class name

- 35,448
- 8
- 62
- 86

- 235
- 1
- 2
- 14
Here is the code that you should write in app delegate.
UIViewController *vc=[[UIViewController alloc]initWithNibName:@"vc1" bundle:nil];
UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];
view.backgroundColor=[UIColor redColor];
[vc setView:view];
self.navme=[[UINavigationController alloc]initWithRootViewController:vc];
self.window.rootViewController = self.navme;

- 5,278
- 43
- 65
- 115
For Swift 3.0, using filter:
let desiredController = self.navigationController!.viewControllers.filter { $0 is YourController }.first!
self.navigationController!.popToViewController(desiredController, animated: true)

- 1,539
- 14
- 21