I want to create a single view application using navigation controller.
How can I do that or post a link for the same?
I want to create a single view application using navigation controller.
How can I do that or post a link for the same?
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
And that will add your navigation controller.
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