-1

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

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

5
  • 2
    Why do you want a navigation controller in a single view application? Commented Nov 18, 2015 at 16:45
  • Thats what my professor wanted me to do Commented Nov 25, 2015 at 22:37
  • your answer shoes how to do it using storyboard, but I wanted to do it without storeyboard Commented Nov 26, 2015 at 5:38
  • I have a new problem, I would tag you over there. It would be very kind of you if you could answer that Commented Nov 26, 2015 at 5:39
  • I'll take a look. I thought that I put the code under the way to do it in the storyboard. Scroll to the bottom of the post. Commented Nov 26, 2015 at 14:27

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.