Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - UITableViewController with navigation bar

Tags:

xcode

ios

swift

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)

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.

enter image description here

and

enter image description here Thanks,

enter image description here

like image 896
ksa_coder Avatar asked Jan 11 '16 10:01

ksa_coder


People also ask

How do I add a navigation bar in Swift?

Start with Navigation ControllerCreate a single view application in Xcode. Add two view controller into your storyboard. Create two different swift files for those view controllers and set identifiers for them. Take a button in each view controller, set constrain for them and customize as you want.

How do I customize the navigation bar in Swift?

Go to the ViewController. swift file and add the ViewDidAppear method. a nav helper variable which saves typing. the Navigation Bar Style is set to black and the tint color is set to yellow, this will change the bar button items to yellow.


2 Answers

If you are coming from another controller to TableViewController then

try this code

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

self.navigationController?.presentViewController(nav, animated: true, completion: nil)
like image 196
hellosheikh Avatar answered Sep 29 '22 10:09

hellosheikh


Click the ordersViewController. Then in the top bar Editor > Embed In > Navigation Controller and remove the navigationbar you currently have in the VC.

like image 31
Ted Huinink Avatar answered Sep 29 '22 11:09

Ted Huinink