presentViewController不显示选项卡栏或导航栏 [英] presentViewController does not show Tab Bar or Navigation Bar

查看:117
本文介绍了presentViewController不显示选项卡栏或导航栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Swift的新手,并且一直在努力解决这个问题。

I am new to Swift and have been struggling with this for a while.

我正在尝试根据登录状态将用户重定向到Loginviewcontroller或Homeviewcontroller。

I am trying to redirect users based on login status to either "Login" viewcontroller or "Home" viewcontroller.

Homeviewcontroller有NavigationBar和TabBar,它显示了一个表。但是,当我使用以下代码时,我只看到表格。根本没有显示NavigationBar和TabBar。

"Home" viewcontroller has NavigationBar and TabBar and it shows a table. But, when i use the following code, i see only the table. NavigationBar and TabBar are not shown at all.

var view = self.storyboard?.instantiateViewControllerWithIdentifier("HomeViewController") as UIViewController
self.presentViewController(view, animated: true, completion: nil)

这是我的故事板: https://www.dropbox.com/s/dkcz45n8000gua6/storyboard。 png?dl = 0

任何帮助都将不胜感激!

Any help would be appreciated!

编辑(使用TabBarController) :

Edit (used TabBarController):

var view = self.storyboard?.instantiateViewControllerWithIdentifier("MainTabController") as UITabBarController
self.presentViewController(view, animated: true, completion: nil)


推荐答案

你的问题与快速的新手无关;它与不了解故事板有关。如果您实例化HomeViewController并呈现它,那么这就是您将获得的全部内容。嵌入在故事板中的标签栏控制器和导航控制器中的事实对于刚刚实例化的裸控制器来说并不已知。您应该实例化标签栏控制器并显示它。它将负责实例化其任何子节点,导航控制器将负责实例化其根视图控制器。

Your problem has nothing to do with being new to swift; it has to do with not understanding storyboards. If you instantiate HomeViewController, and present it, then that's all you will get. The fact that it's embedded in a tab bar controller and navigation controller in the storyboard is not "known" to this bare controller you just instantiated. You should instantiate the tab bar controller instead, and present it. It will take care of instantiating any of its children, and the navigation controller will take care of instantiating its root view controller.

这篇关于presentViewController不显示选项卡栏或导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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