如何设置的rootViewController
的UINavigationController
通过以外的方法initWithRootViewController
?
我想用initWithNavigationBarClass:toolbarClass:
提供一个自定义工具栏我NavigationController,所以我不认为我可以使用initWithRootViewController
。
如何设置的rootViewController
的UINavigationController
通过以外的方法initWithRootViewController
?
我想用initWithNavigationBarClass:toolbarClass:
提供一个自定义工具栏我NavigationController,所以我不认为我可以使用initWithRootViewController
。
您可以通过调用解决这个setViewControllers
。
像这样:
UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[MyNavigationBar class] toolbarClass:[UIToolbar class]];
[navigationController setViewControllers:@[yourRootViewController] animated:NO];
知识共享使用斯威夫特:
从比应用其他delegate.swift类改变根视图控制器
let appdelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
var homeViewController = mainStoryboard.instantiateViewControllerWithIdentifier("HomeViewController") as! HomeViewController
let nav = UINavigationController(rootViewController: homeViewController)
appdelegate.window!.rootViewController = nav
希望有人这样会很有帮助。
编辑:
更改RootViewController的动画可与实现:
UIView.transitionWithView(self.window!, duration: 0.5, options: UIViewAnimationOptions.TransitionFlipFromLeft, animations: {
self.window?.rootViewController = anyViewController
}, completion: nil)
我们可以写太相似了归纳法这一点。
这个工作对我来说,希望它可以帮助你,
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
在SWIFT 3.0 xcode8.1
在常规设置中删除主界面:主< - 这个主界面后:
class AppDelegate...
var window: UIWindow?
fun application...
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = UINavigationController(rootViewController: NewYourController)
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()
})