来自storyboard的实例化NavigationController引用相同的RootViewController

时间:2018-02-26 16:06:51

标签: ios xcode interface-builder uistoryboard

我正在从故事板中实例化导航控制器,我已经为其定义了根视图控制器。

如果我按如下方式实例化多个navigationcontroller:

        let nav = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "CategorizedArticleNavigationController") as! UINavigationController
        let rootVC = nav.viewControllers.first as! CategorizedArticlesViewController
        let nav_1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "CategorizedArticleNavigationController") as! UINavigationController
        let rootVC_1 = nav.viewControllers.first as! CategorizedArticlesViewController            
        self.present(rootVC, animated: true, completion: nil)

尝试以模态方式呈现后出现异常:

  

由于未捕获的异常而终止应用   'NSInvalidArgumentException',原因:'应用程序试图呈现   modally一个活跃的控制器......'

调试后,令我惊讶的是,我发现了nav!= nav_1

但是

rootVC == rootVC_1

然后我尝试以模态方式呈现导航,因为它发现它的根vc已经被呈现了。

有没有人见过这个?我应该提交错误吗?或者这是出于某种目的?

更新:这绝对是我的错误,@ Samntha澄清说明

enter image description here

谢谢。

0 个答案:

没有答案
相关问题