0

I am an Objectie-C developer. for the root view navigation i used the below code in Objectie-c

 FirstViewController *fvc=[[FirstViewController alloc]init];
 UINavigationController *nv=[[UINavigationController alloc]initWithRootViewController:fvc];
 self.window.rootViewController=nv;

for my new project I am making it in swift.I just want to make RootView navigation from AppDelegate.swift.

Code cracker
  • 3,105
  • 6
  • 37
  • 67

2 Answers2

2

Check below code. first we create window. then alloc init viewcontroller. and then alloc navigation controller with rootcontroller as viewcontroller. and Window's root controller as navigation controller.

var window: UIWindow?
var navC : UINavigationController?
var vc:ViewController?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
    // alloc init window
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)

    // view controller
    self.vc = ViewController(nibName: "ViewController", bundle: nil);

    // create navigation controller with root = vc.
    self.navC = UINavigationController(rootViewController: self.vc!);
    self.navC?.navigationBar.hidden = true;

    // window's root controller as navigation controller.
    self.window?.rootViewController = self.navC
    self.window?.makeKeyAndVisible()

    return true
}

Maybe this will help you.

ChintaN -Maddy- Ramani
  • 5,156
  • 1
  • 27
  • 48
1
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {

 var rootVie: FirstViewController = FirstViewController()  // this is allocation method in swift

 if let window = self.window{
        window.rootViewController = rootVie
 }

 return true
}

need referene use this link

Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143