xcode Swift - 带有导航栏的 UITableViewController

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34719201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 08:25:03  来源:igfitidea点击:

Swift - UITableViewController with navigation bar

iosxcodeswift

提问by ksa_coder

I am facing an issue with one of my table view controllers. I don't seem to be able to get the navigation bar to show on top no matter what option I enable (maybe I am missing something).

我的一个表视图控制器遇到了问题。无论我启用什么选项,我似乎都无法让导航栏显示在顶部(也许我遗漏了一些东西)。

I tried the following:

我尝试了以下方法:

  • Selecting the controller in storyboard and going to attributes inspector and ensuring that top bar is set to Translucent Navigation (didn't work)
  • In the viewWillAppear function, I wrote: (didn't work)
  • 在故事板中选择控制器并转到属性检查器并确保顶部栏设置为半透明导航(不起作用)
  • 在 viewWillAppear 函数中,我写道:(不起作用)

self.navigationController?.navigationBarHidden = false

self.navigationController?.navigationBarHidden = false

Attached is also an image of the controller discussed. How can I do show the top bar? otherwise the results are ugly since the records showing (rows) are starting from the very top. I do not wish to use UIEdgeInsetsMake to fix it if possible.

还附上了所讨论的控制器的图像。我怎样才能显示顶部栏?否则结果很难看,因为显示(行)的记录是从最顶部开始的。如果可能,我不希望使用 UIEdgeInsetsMake 来修复它。

enter image description here

在此处输入图片说明

and

enter image description hereThanks,

在此处输入图片说明谢谢,

enter image description here

在此处输入图片说明

回答by Ted Huinink

Click the ordersViewController. Then in the top bar Editor > Embed In > Navigation Controllerand remove the navigationbaryou currently have in the VC.

单击ordersViewController。然后在顶部栏中的Editor > Embed In > Navigation Controller并删除navigationbar您当前在 VC 中拥有的。

回答by hellosheikh

If you are coming from another controller to TableViewControllerthen

如果您来自另一个控制器,TableViewController那么

try this code

试试这个代码

let nav : UINavigationController = UINavigationController(rootViewController: self.storyboard!.instantiateViewControllerWithIdentifier("YourControllerName") as UIViewController)

self.navigationController?.presentViewController(nav, animated: true, completion: nil)

回答by Andorath

You have to embed your UITableViewControllerin a UINavigationController.

你必须将你的嵌入UITableViewControllerUINavigationController.