我有一个UITableViewController已经嵌入到NavigationController. 但是,当我呈现视图时,导航栏没有显示。
呈现TableViewController(它的故事板 ID 是:)SelectServicesController:
if let selectServicesController = self.storyboard?.instantiateViewControllerWithIdentifier("SelectServicesController") as? UITableViewController {
self.navigationController?.presentViewController(selectServicesController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
这是我构建时的样子(导航栏不显示):
所以我只是这样做了,但一开始根本无法让它出现。然后想通了,您只需要选择导航控制器并将其设置为?is initial View Controller
然后为了显示所有内容,我将其添加到viewDidLoad导航控制器呈现的视图中。这一步是可选的。
self.navigationController?.navigationBar.barTintColor = UIColor.redColor()
self.navigationController?.navigationBar.tintColor = UIColor.blackColor()
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.blackColor()]
navigationController?.navigationBar.hidden = false
Run Code Online (Sandbox Code Playgroud)
这就是它的样子
mmmm 黑底红希望对你有帮助。
您正在展示一个 UITableViewController,它没有作为父级的导航控制器(即使您的 Storyboard 首先拥有它,但您实际上并没有使用它)。
您可以通过执行以下操作来解决此问题:
if let selectServicesController = self.storyboard?.instantiateViewControllerWithIdentifier("SelectServicesController") as? UITableViewController {
let navigationController = UINavigationController(rootViewController: selectServicesController)
self.navigationController?.presentViewController(navigationController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)
或者通过将导航控制器设置为故事板的初始视图控制器,然后像这样调用它:
if let selectServicesController = self.storyboard?.instantiateInitialViewController() {
self.navigationController?.presentViewController(selectServicesController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)