Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar not showing iOS swift

I am having multiple view controller in my application. I want to hide navigationbar in my first view controller. So I use the following code to hide the navigation bar

navigationController?.setNavigationBarHidden(navigationController?.navigationBarHidden == false, animated: true); 

Now I want to add navigation bar in some other viewController but, my navigation bar not visible in that viewcontroller. Why it is happening?

My storyboard showing the navigation bar but once I try to run my application it is gone.

If I hide navigation bar from one view controller then we can't use navigation controller, Is it so? I hope I am wrong. Then what are the reasons for navigation bar not shown?

EDIT:

Also I want my view controller in portrait mode only. So I did the following Is that causing the issue?

extension UINavigationController{     public override func shouldAutorotate() -> Bool {         if (UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeLeft ||             UIDevice.currentDevice().orientation == UIDeviceOrientation.LandscapeRight ||             UIDevice.currentDevice().orientation == UIDeviceOrientation.Unknown) {                 return false         }         else {             return true         }     }          public override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {         return [UIInterfaceOrientationMask.Portrait ,UIInterfaceOrientationMask.PortraitUpsideDown]     }       } 

Edit 1:

I am using following code to move from one view controller not link from the storyboard. Is that causing issue now?

 let storyboard = UIStoryboard(name: "Main", bundle: nil)         let secondViewController = storyboard.instantiateViewControllerWithIdentifier("HomeVC")         presentViewController(secondViewController, animated: false, completion: nil) 

Edit 2:

Please check my following screenshots. Which are my settings for secondview controller

enter image description here

enter image description here

Edit 3:

Here is my navigation controller attribute inspector enter image description here

like image 630
Amsheer Avatar asked Nov 13 '15 09:11

Amsheer


People also ask

How do I show hidden navigation bar?

Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I create 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 use the navigation bar in IOS?

macOS doesn't provide a navigation bar. To enable navigation in a macOS app, you often use a sidebar or a navigation control like a Back button in a toolbar. Also, you typically display the title of a macOS window in the title bar.

What is a navigation controller Swift?

A navigation controller is a container view controller that manages one or more child view controllers in a navigation interface. In this type of interface, only one child view controller is visible at a time.


1 Answers

Navigation Controller is a controller, which has stack of view controllers. So if you have something like this:

NAV -> A -> (segue) B

Even if you'll hide navigation bar you still should be able to make segues. Also can't you just unhide navigation bar in second (B) view controller in viewWillAppear? And in first the same way hide it on viewWillAppear.

edit: Final solution to the problem: Use:

 let controller = storyboard.instantiateViewControllerWithIdentifier("HomeVC")  self.navigationController!.pushViewController(controller)  

instead of:

let secondViewController = storyboard.instantiateViewControllerWithIdentifier("HomeVC") presentViewController(secondViewController, animated: false, completion: nil) 

Because pushViewController will add secondViewController to its stack. presentViewController was replacing your navigation controller that's why you couldn't see navigation bar.

like image 130
Makalele Avatar answered Sep 20 '22 13:09

Makalele