我试图在UIViewController中使用swift中的setRootViewController,而不是来自app delegate。
我发现了一些关于堆栈溢出的问题,但是他们已经解释过从app delegate那里做的所有问题。但是,我想从UIViewController中创建它并将UITabBarController设置为rootViewController
这就是我在目标c中做到的方式
UITabBarController *main = [self.storyboard instantiateViewControllerWithIdentifier:@"main"];
[[[[UIApplication sharedApplication] delegate] window] setRootViewController:main];
我想在swift中做同样的事情。有什么方法可以在swift中完成,还是我需要使用segue?
答案 0 :(得分:2)
我使用以下代码行完成:
UIApplication.sharedApplication().delegate?.window??.rootViewController = mainViewController