Swift ios设置了一个新的根视图控制器 [英] Swift ios set a new root view controller

查看:1104
本文介绍了Swift ios设置了一个新的根视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以设置新的根VC?



我的应用程序使用uinavigation控制器获取init,该控制器具有作为根VC的表视图。 / p>

然后从表格视图中我运行另一个segue到登录窗口(以模态呈现)如果你然后登录你最终进入红色 VC /帐户页面。我现在要做的是将红色VC设置为应用程序的新根VC,并删除所有底层VC。这样我就可以显示菜单按钮/图标而不是后退按钮



我发现了这个,但我不明白如何使用它:

 让storyboard:UIStoryboard = UIStoryboard(名称:Main,bundle:NSBundle.mainBundle())
let yourViewController:ViewController = storyboard .instantiateViewControllerWithIdentifier(individualIdentifier)为! ViewController

让navigationController = self.window?.rootViewController为! UINavigationController
navigationController.setViewControllers([yourViewController],animated:true)

但我无法得到它工作。因此可以使图片中的红色vc充当新的根VC。



解决方案

可能你应该试试这个

 让mainStoryBoard = UIStoryboard( name:Main,bundle:nil)
让redViewController = mainStoryBoard.instantiateViewControllerWithIdentifier(individualIdentifier)为! ViewController
让appDelegate = UIApplication.sharedApplication()。委托为! AppDelegate
appDelegate.window?.rootViewController = redViewController


I wonder if its possible to set a new root VC?

My app gets init with a uinavigation controller that has a table view to be the root VC.

Then from the table view I am running another segue to a login window (present modally) If you then login you end up in the red VC/account page. What I want to do now is to set the red VC to be the new root VC of the app, and remove all underlying VC's. So that I can show a menu button/icon instead of a "Back" button

I have found this but I dont understand how to use it:

let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
        let yourViewController: ViewController = storyboard.instantiateViewControllerWithIdentifier("respectiveIdentifier") as! ViewController

        let navigationController = self.window?.rootViewController as! UINavigationController
        navigationController.setViewControllers([yourViewController], animated: true)

But I cannot get it to work. So is it possible to make the red vc in the picture act as the new root VC.

解决方案

May be you should try this

 let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
 let redViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("respectiveIdentifier") as! ViewController
 let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
 appDelegate.window?.rootViewController = redViewController

这篇关于Swift ios设置了一个新的根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆