如何在ios swift中使用xib将UINavigationController设置为rootviewcontroller?

时间:2015-08-19 10:01:11

标签: ios swift uinavigationcontroller

这里我尝试将navigationcontroller设置为rootviewcontroller,但它显示错误。如何解决它。

额外的论点'捆绑'在电话中。

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
}

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

把它在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];