我正在使用以下代码以编程方式导航到另一个 ViewController。它工作得很好,但它在某种程度上隐藏了navigation bar
. 我该如何解决?(导航栏是通过嵌入ViewController
in the navigation controller
如果这很重要的话。)
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("nextView") as NextViewController
self.presentViewController(nextViewController, animated:true, completion:nil)
Swift 5
默认的模式呈现样式是卡片。这会在顶部显示上一个视图控制器,并允许用户滑开所呈现的视图控制器。
要保留旧样式,您需要修改将要呈现的视图控制器,如下所示:
newViewController.modalPresentationStyle = .fullScreen
这对于以编程方式创建的控制器和故事板创建的控制器来说都是相同的。
Swift 3
使用以编程方式创建的控制器
如果您想导航到以编程方式创建的控制器,请执行以下操作:
let newViewController = NewViewController()
self.navigationController?.pushViewController(newViewController, animated: true)
使用 StoryBoard 创建控制器
如果您想导航到 StoryBoard 上带有标识符“newViewController”的控制器,请执行以下操作:
let storyBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let newViewController = storyBoard.instantiateViewController(withIdentifier: "newViewController") as! NewViewController
self.present(newViewController, animated: true, completion: nil)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)