简体   繁体   English

UINavigationController topViewController没有显示

[英]UINavigationController topViewController not showing up

I'm using the code below to try to change the displayed viewController in a UINavigationController: 我正在使用下面的代码来尝试更改UINavigationController中显示的viewController:

var mainStoryboard = UIStoryboard(name: "Main", bundle: nil)

var navigationController:UINavigationController = mainStoryboard.instantiateViewControllerWithIdentifier("navController") as UINavigationController
var homeViewController: UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("HomeView") as UIViewController

navigationController.popViewControllerAnimated(false)
navigationController.pushViewController(homeViewController, animated: false)

var topController = navigationController.topViewController as UIViewController
println("homeview id:\(homeViewController.restorationIdentifier)")
println("topview id: \(topController.restorationIdentifier)")  

here is the storyboard: 这是情节提要:
在此处输入图片说明
First question: Why when I remove the popViewControllerAnimated function call in this exemple, the top view is still the LoginView even if I pushed the HomeView ? 第一个问题:为什么在这个示例中删除popViewControllerAnimated函数调用时,即使我按下HomeView,顶视图仍然是LoginView? (Isn't it supposed to be the last pushed view Controller ?) (不是它应该是最后一个推送视图控制器吗?)
Second question: When I keep the popViewControllerAnimated function call I got the right top view (my topView is now HomeView as expected) but the displayed ViewController on the screen is still the loginView. 第二个问题:当我保持popViewControllerAnimated函数调用时,我得到了正确的顶视图(我的topView现在像预期的那样是HomeView),但是屏幕上显示的ViewController仍然是loginView。 Why the new TopViewController doesn't show up then ? 为什么新的TopViewController不出现呢?
thanks 谢谢

The problem is that your instantiating a new navigation controller rather than accessing the one that's automatically instantiated when your app starts up. 问题在于您实例化了一个新的导航控制器,而不是访问在应用启动时自动实例化的控制器。 Instead of this line, 代替这条线,

var navigationController:UINavigationController = mainStoryboard.instantiateViewControllerWithIdentifier("navController") as UINavigationController

you should use this, 你应该用这个

var navigationController:UINavigationController = self.view.window.rootViewController // it should just be self.window.rootViewController if this code is in the app delegate

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 简单标题未显示在UINavigationController中 - Simple Title not showing up in UINavigationController 自定义UINavigationController中的UIBarButtonItem未显示 - UIBarButtonItem in custom UINavigationController not showing up UINavigationController的addChildViewController和topViewController之间的相互作用 - Interplay between UINavigationController’s addChildViewController and topViewController 在UINavigationController中,topViewController,visibleViewController,presentsViewController有什么区别? - In UINavigationController what is the difference between topViewController, visibleViewController, presentedViewController? 取消按钮未显示在iPad模式下的UINavigationController中 - Cancel button not showing up in UINavigationController in modal for iPad 当UIViewController位于UINavigationController内部时,键盘未显示 - Keyboard is not showing up when UIViewController is inside UINavigationController 无法将类型'UINavigationController'的值转换为'jacrs_ios.TopViewController' - Could not cast value of type 'UINavigationController' to 'jacrs_ios.TopViewController' 将UINavigationController添加到UITabBarController,而不显示所有视图中的Tab Bar - Add UINavigationController to UITabBarController without Tab Bar showing up in all views UINavigationController没有显示后退按钮 - UINavigationController not showing back button uitabbar的topviewcontroller - topviewcontroller for uitabbar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM