我想以编程方式转到新的 ViewController,但是当我这样做时,我的 tabBar 消失了。
if user == usernameStored && pass == passwordStored{
print("Good")
let vc = self.storyboard?.instantiateViewController(withIdentifier: "home")
self.present(vc!, animated: true, completion: nil)
}
最佳答案
从您的代码来看,这不是以编程方式进行的 segue
。实际上,您在现有的任何内容之上呈现
一个viewController
。因此 tabBarController
被覆盖了。
要在代码中使用segue
,应该是这样的。 - homeSegueID
是您在 Storyboard中创建 segue
时提供的 identifier
。
performSegue(withIdentifier: "homeSegueID", sender: nil)
如果您只是想在没有 segue
的情况下以编程方式执行此操作,则可以改为执行此操作。 (假设您当前的 ViewController
位于 UINavigationController
堆栈中。
navigationController?.pushViewController(vc, animated: true)
关于ios - TabBar 在程序化 segue 时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43349615/