从子UIViewController中推送UIViewController

时间:2015-09-08 21:12:07

标签: ios swift uiviewcontroller uinavigationcontroller

所以我有一个UINavigationController堆栈。此堆栈中的UIViewControllers之一有UIButton,它添加了一个子UIViewController来实现模态外观(它是一个具有模糊,半透明背景的菜单)。代码如下,工作得很好。

        var childVC = storyboard!.instantiateViewControllerWithIdentifier("Extra") as! UIViewController
        childVC.view.frame = CGRectMake(0, 0, self.view.frame.width, UIScreen.mainScreen().bounds.height)

        self.navigationController?.addChildViewController(childVC)
        self.navigationController?.didMoveToParentViewController(childVC)
        self.navigationController?.view.addSubview(childVC.view)

但在Child UIViewController内部,我需要在堆栈顶部推送UIViewController,即在Parent UIViewController上。我已经尝试了很多东西,但我能得到的最好的是用self.navigationController?.pushViewController打开一个空白屏幕 - 这会运行下一个UIViewController中的代码(例如它打印到控制台)但显然有问题显示黑屏。我也试过self.parentViewController?.navigationController?.pushViewController

编辑:,如果我打印出顶部UIViewController的println(self.navigationController!.viewControllers)中的堆栈viewDidLoad,即显示空白的堆栈UIViewController。它按预期打印:第一个UIViewController,模态UIViewController和顶部<h1>Cascading Style Sheets (CSS)</h1> <p>Cascading Style Sheets (CSS) is a style sheet language used for describing the look and formatting of a document written in a markup language <span class="sidenote" data-source="src1"></span>. Although most often used to change the style of web pages and user interfaces written in HTML and XHTML, the language can be applied to any kind of XML document, including plain XML, SVG and XUL. Along with HTML and JavaScript, CSS is a cornerstone technology used by most websites to create visually engaging webpages, user interfaces for web applications, and user interfaces for many mobile applications <span class="sidenote" data-source="src2"></span>.</p> <h3>References</h3> <ul id='references'></ul>

0 个答案:

没有答案