B.Saravana Kumar
B.Saravana Kumar

Reputation: 1242

how to set UINavigationController as a rootviewcontroller using xib in ios swift?

Here I Have tried to set navigationcontroller as a rootviewcontroller but it shows a error. How to solve it.

Extra argument 'bundle' in call.

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    self.window!.backgroundColor = UIColor.whiteColor()

    let nav = UINavigationController()
    let vc = MyNavigationController(nibName: "MyNavigationController", bundle: nil)

    nav.pushViewController(vc, animated: false)

    self.window!.rootViewController = nav
    self.window!.makeKeyAndVisible()
    nav.setNavigationBarHidden(true, animated: false)


    return true
}

Upvotes: 2

Views: 7187

Answers (2)

Kandhal Bhutiya
Kandhal Bhutiya

Reputation: 198

Take it its in objective-C

 self.window=[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

        viewcontroller=[[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];

        UINavigationController *navigation=[[UINavigationController alloc] initWithRootViewController:viewcontroller];

        self.window.rootViewController=navigation;
        [window makeKeyAndVisible];

Upvotes: 2

Bhavesh Nayi
Bhavesh Nayi

Reputation: 3656

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()

OR

var navigationController = UINavigationController(rootViewController: viewController));

Upvotes: 2

Related Questions