How to pop UIViewController when no NavigationController? - ios

My initial scene has a navigation controller embedded. This scene links to a UITableViewController scene. The tableview scene doesn't know anything about the navigation controller.
In the tableview scene, I've added a navigation bar and left button called back. How do I get back to the previous scene?
I have the following action associated with the back button:
self.navigationController?.popViewControllerAnimated(true)
But it doesn't do anything because self.navigationController is nil.

If your navigationController is nil, then your scene must have been displayed modally, not pushed onto a nav controller. Instead of popping it, you have to call dismissViewController on it.
A better approach than using a left button item to navigate is to use the nav bar's built-in functionality by setting a custom backIndicatorImage and mask.

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.

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.

Dismiss Modally presented view makes tab bar controller (kind of) reset

I have an app which has tab bar controller as main controller. Each tab has a series of views with navigation controller and I normal push and pop those view in stack.
Weird problem is
Case 1 : If I create a UINavigationController and make a new viewController as its root, and present this NavigationController. Within this new navigation stack, I can easily present a view modally and dismiss it without a problem.
Case 2: Now without make a new UINavigationController, I present a view, and when I dismiss a view, the view beneath is behave weirdly. For example, it's the presenting view was UICollectionView, it just scroll back to 1st cell, like it's doing "reload" action and "scrollTo" the first cell. If the presentingView is a pushed view from rootView, it will just popToRoot view, which is definitely not intended.
I didn't have this problem until I implement UITabbarController, so I guess, I should know more that's going on under the hood when presenting a view and dismiss a view in UITabbarController.
I GUESS, when dismiss a view in UITabbarController view, it sort of "RESET" everything to the very first view of it's current tab. I really am not sure it's trure though.
I know it's kind of conceptual, but I can't help to think there must be something critical I am missing here.
I made silly mistake that I sublclass UITabbarController and define navigation controlllers in viewDidAppear instead viewdidLoad, so when I make the window's rootview to tabbar controller, the navigation controllers are not set properly. That's why all punky things happened. It would be nicer if just crash instead of this weird behaviors.
You can try this to go back to your first viewcontroller.
- (IBAction)buttonPressedFromVC2:(UIButton *)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
} // This is going back to VC1.
This method is will be in second viewcontroller.m file. It is button click method.

Keep UIView while animating navController

How can I animate in a new uinavigation controller but keep the same uiview in the window?
I've seen this done in the opposite - a navController stay in place while a container view changes a view controller as a child view controller, but I want the opposite:a main view, a mapview, to remain in the window at all times while a new vc2 slides in from a push segue which will show a different navBar title and uibarbutton items. This is important because I need the mapview from VC1 to replicate in VC2, or to that effect.
Can this be done and how? Thank you for suggestions all,
It would probably be better to do this without a navigation controller. You can create a custom container controller with a navigation bar at the top. You can add vc2 as a child of your container controller, remove the map view from vc1, add it to the view of vc2, and remove vc1 from the container controller. This would all be done with no animation, so the user shouldn't see anything happening in the main view. You can call pushNavigationItem:animated: on the navigation bar to animate in the new navigation item.

Modal Segue Into Navigation Controller with No Nav Bar

In my storyboard I have a view with a segue into a new view that's embedded into a Navigation Controller (so the segue points to the navigation controller). I have the segue set to a Modal transition, however when the new view is animating up, it contains the standard blue navigation bar above the view (which then animates out of view).
Here's what it looks like mid segue: http://i.imgur.com/3eqAQ.png
How do I make it so the modal view animates up but without the navigation bar?
I have tried hiding the navigation bar in the embedded view's init, viewWillAppear, and vieWillLoad methods and that doesn't work.
I event went so far as to create a custom subclass of UINavigationController and set the navigation controller in the storyboard to it.
Thanks!
This may sound pretty simple, but have you tried hiding the navigation bar immediately before the modal segue starts? I had this problem when presenting a modal view controller and adding a [self.navigationController setNavigationBarHidden:YES] immediately before the presentation did the trick for me.
I had almost the same problem, but I wanted to get a navigation bar for my modal transition, as it was always hidden.
There may be two ways for you to remove the navigation bar:
Make sure that your view controller is not embed in a navigation controller, as it would put one by default
Check the "Top Bar" attribute of your previous controller in the workflow and work with none/inferred values depending on your storyboard.
Regards

Resources