以外の方法rootViewControllerでを設定するにはどうすればよいですか?UINavigationControllerinitWithRootViewController
NavigationController のカスタム ツールバーを提供するために使用したいinitWithNavigationBarClass:toolbarClass:ので、使用できないと思いますinitWithRootViewController。
以外の方法rootViewControllerでを設定するにはどうすればよいですか?UINavigationControllerinitWithRootViewController
NavigationController のカスタム ツールバーを提供するために使用したいinitWithNavigationBarClass:toolbarClass:ので、使用できないと思いますinitWithRootViewController。
を呼び出すことでこれを解決できますsetViewControllers。
このような:
UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[MyNavigationBar class] toolbarClass:[UIToolbar class]];
[navigationController setViewControllers:@[yourRootViewController] animated:NO];
迅速なバージョン:
let navigationController = UINavigationController(navigationBarClass: MyNavigationBar.self, toolbarClass: UIToolbar.self)
navigationController.setViewControllers([yourRootViewController], animated: false)
これは私のために働きます、それがあなたを助けることを願っています、
let rootVC:LoginViewController = self.storyboard?.instantiateViewControllerWithIdentifier("LoginViewController") as! LoginViewController
let nvc:UINavigationController = self.storyboard?.instantiateViewControllerWithIdentifier("RootNavigationController") as! UINavigationController
nvc.viewControllers = [rootVC]
UIApplication.sharedApplication().keyWindow?.rootViewController = nvc
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let yourNewRootView = storyboard.instantiateViewControllerWithIdentifier("yourNewRootView") as? yourNewRootView
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
UIView.transitionWithView(self.window!, duration: 0.1, options: [UIViewAnimationOptions.TransitionFlipFromRight,UIViewAnimationOptions.TransitionFlipFromLeft], animations:
{
// animation
}, completion: { (finished: Bool) -> () in
self.window?.rootViewController = nil
self.window?.rootViewController = yourNewRootView
self.window?.makeKeyAndVisible()
})