-1

I want to create a single view application using navigation controller.

How can I do that or post a link for the same?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tushar
  • 129
  • 1
  • 2
  • 10

1 Answers1

3

I am not sure why you would want a navigation controller in a single view application, but here is how you do it.

If you are using the Storyboard select the view controller icon on your inital ViewController, then:

Go to Editor -> Embed In -> Navigation Controller

enter image description here

And that will add your navigation controller.

enter image description here

If you want to do it programmatically, then you will want to implement this code in the AppDelegate's method didFinishLaunchingWithOptions:

UIViewController *bbp=[[UIViewController alloc]initWithNibName:@"UIViewController" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
// [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
  [self.navigationController pushViewController:passcodeNavigationController animated:YES];
  [passcodeNavigationController release];

If you are ever interested in Swift I found this thread, and the accepted answer seemed pretty good:

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
var nav1 = UINavigationController()
var mainView = ViewController(nibName: nil, bundle: nil) //ViewController = Name of your controller
nav1.viewControllers = [mainView]
self.window!.rootViewController = nav1
self.window?.makeKeyAndVisible()

And here is the converted code (might be buggy) from the Objective-C:

var bbp: UIViewController = UIViewController(nibName: "UIViewController", bundle: nil)
var passcodeNavigationController: UINavigationController = UINavigationController(rootViewController: bbp)
// [self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
navigationController.pushViewController(passcodeNavigationController, animated: true)
passcodeNavigationController
Community
  • 1
  • 1
Caleb Kleveter
  • 11,170
  • 8
  • 62
  • 92