Programming Transition Loses Navigation Bar - ios

I'm having an issue with my main.storyboard file. I changed the settings of my app so that the start screen is the main.storyboard file, rather than LaunchScreen.xib. The initial ViewController is the NavigationController, and the second is my SplashScreeViewController. (I created my own splash screen in the storyboard so that I could change it with additional code.) I use a line of code in my splash screen to later transition to the second view controller. Here it is:
var controller:UIViewController = self.storyboard?.instantiateViewControllerWithIdentifier("Second") as! ViewController
controller.modalTransitionStyle = .CrossDissolve
self.presentViewController(controller, animated: true, completion: nil)
For some reason, when I transition to that second ViewController, the navigation bar that should be at the top (of the second ViewController) isn't there, opposite of what was shown in the main.storyboard file. I tried to add an invisible, disabled button to the splash screen as to add a connection between the two view controllers, and therefore adding a navigation bar to the second, but when the splash transitions on its own, no navigation bar appears on the second.
Is there a way I could have a navigation bar on my second view controller without dragging one in, nor programming it in? I would like to use the one Xcode provides when you create a new connection between controllers.
Thanks in advance to all who reply.
*(I apologize for the lack of pictures to help describe my problem. I don't have enough 'reputation' to do so.)

You need to embed your Second view controller on a Navigation Controller, and then instantiate that navigation controller instead.

This might solve the problem - It looks like you are presenting a modal view controller when you probably want to be pushing your view controller from your initial navigation controller with pushViewController

Related

How to keep NavigationController when performSegue from embeded tableviewcontroller

In the bottom left viewcontroller i have a searchbar at the top that call the tableview at the top , the problem is that i want to segue to the right viewcontroller with detail of it, but of course i'm losing my navigationController so when i'm into the right viewcontroller i can't go back anymore, how should i do to go back to my original Viewcontroller ?
Add Navigation Controller as the starting view in storyboard. And then Link RootViewController to it. This will ensure navigation bar in all the views coming next.
you may hide navigation bar in the view where not needed as
self.navigationController?.isNavigationBarHidden = true
push newViewController instead of presenting
Also please check, if you are presenting it modally. Modal segues take over the whole screen, so any navigation bars, tool bars, or tab bars that are in the presenting controller will be covered up. If you want a navigation bar on this modal controller, you'll need to add one specifically to it, and add any buttons you want to that new navigation bar (or tool bar). If you don't want to do this, then don't present it modally, do a push to it.

Bar item button not displayed at runtime but visible at design time in a modal view

I have being trying different things and looking around for a while without finding an answer to my problem. Maybe I'm doing something fundamentally wrong.
The sample application consists of:
A first view controller that displays a second view controller using a segue. This works fine.
A second view controller, in which I have simulated the display of a third view programmatically, which contains a bar item button (named "Done") that I would like to display.
The bar item button in the third view controller is not displayed at runtime but is displayed in IntefaceBuidler at design time.
This third view controller needs to be displayed modal.
What I'm doing wrong to display this bar item button?
A sample project illustrating the problem is available here.
Below a screen capture of the bar item button at design time:
Below a screen capture of the bar item button not showing at design time:
PS:
Please disregard the "Unknown class ThirdViewControlller in Interface Builder file.", since the ThirdViewController is displayed fine at runtime. Also, the "Done" button in the middle of the view works fine.
In SecondViewController you need to push the third onto the navigation controller stack like so:
self.navigationController?.pushViewController(thirdViewController, animated: true)
You are currently presenting it as a modal. Also, you've unnecessarily added a second UINavigationController to your storyboard (for the third view controller)
If you want to present a modal, then you'd need to embed the controller in a navigation controller:
let navController = UINavigationController(rootViewController: thirdViewController)
self.present(navController, animated: false)
If you prefer to keep this within the storyboard, then you need to provide a identifier for the UINavigationController and insatiate that in your function.
The above button is a navigation bar item that will only be displayed on the navigation bar . For achieving your desired result , you first have to embed the navigation controller at least in your second viewcontroller and then you should do a push segue rather than modal . Navigation controller can be added by
whith your second viewcontroller selected go to Editor\Embed In\Navigation Controller
for pushing the viewcontroller programatically onto user navigation controller's stack use
self.navigationController?.pushViewController(nextViewController, animated: true)

Navigation Controller Header is not showing

So, here I basically have this layout
but when I build successfully I am not able to see the title of the navigation controller.
What can I do?
This is what you want to emulate:
Set the UITabBarController as is Initial View Controller
add a relationship to each scene, whether it is a UINavigationController or not
If a scene is a UINavigationController, it will behave like any root navigation controller, with its own view stack, back button, an so forth.
Running the app above, then tapping on Item 2 will present this navigation controller:
If you cannot make the UITabBarController the initial View Controller at launch, you can make it become root later on using this technique:
let newViewController = self.storyboard?.instantiateViewControllerWithIdentifier("id")
as? UIViewController
self.view.window?.rootViewController = newViewController
This will present the architecture above, albeit without animation (nor any way to navigate back). Perfect for onboarding or login screens.
Tested on Xcode 7+, iOS 9+
Make your TabBar Controller the initial view, And make sure to remove the navigation controller that's linked to it, Then it should work fine.

Prevent removing overlayed controller from memory when switching tab in UITabView

I have a TabViewController. It contains a MapViewController with a NavigationItem (title bar with menu items). The MapViewController for itself modally shows another Controller (the settings) which also has a NavigationItem. My problem:
If the settings controller is shown and one switches to another tab and back (the settings controller is still open then) the underlying MapViewController is removed from memory so when the settings controller is dismissed, it shows a black screen where the map controller should be. How can I force to keep the map controller in memory?
All segues expect from modally "over current context" will cover the TabView, this should not happen, so it has to be a modal segue.
definesPresentationContext on the MapViewController preserves the map, yes. But when calling the settings controller it is embedded in the map view under the map view navigation item so there are 2 navigation bars. This obviously also mustn't happen.
The problem lies within the modal view. When switching back, the tabbar presented the settings controller but is unable to know from what it was modally called. Define the map view controller as current context and dismiss the navigation bar of the presenting view controller in the viewDidLoad of the upcoming settings controller. When using the setNavigationBarHidden(true, animated: true) it even has a nice look.
The viewWillAppear is a nice place to get it back to place and keep the animations in sync.

How to "virtually" tap back button in Navigation Bar

I have app, where is Segmented Control inside of my Navigation Bar. Under navigation bar I have 3 containers. In these containers I have Table View Controllers. If you tap on segmented control, one TVC appear and others disappear (container1.hidden = true and so on).
Problem is when I press "save" button which is also in navigation controller - button doesn't trigger "virtual push of back button".
I used following code which works in my other projects (its in button's action which is in VC that contains all container views) but not this time:
if let navController = self.navigationController {
navController.popViewControllerAnimated(true)
}
Image for better insight:
UPDATE: Thanks to # Alexey Bondarchuk I solved it. Comments may be confusing so I just recap problem and solution.
Originally, I had ViewController. To this controller I embed in Navigation Controller. To this Navigation Controller I connected segues. And that was mistake.
So I deleted this embed in navigation controller, made (show) segues directly to my View Controller (which is on screenshot). This automatically created navigation bar and last thing I did was that I put navigation item in it so now my code pop right navigationController. Hope that it's understandable.
I have couple ideas:
Your navigationController equal to 'nil' and .popViewControllerAnimated will never invoked. This may happen if you are using UITabBarController. In this case try to use self.tabBarController?.navigationController instead of self.navigationController.
Your controller presented 'Modally'. In this case you can try to invoke navController.dismissViewControllerAnimatedinstead of navController.popViewControllerAnimated

Resources