Fake UINavigation Bar - ios

I'm making an app in Swift and even though i'm using a navigation controller, there is a particular point where I want to present a view controller rather than make a segue and have the viewController added to the navigation stack.
This view controller i'm presenting is completely disconnected from the rest of the storyboard (it gets reused by a few screens).
To "fake" that it's part of the navigation controller stack, I wanted to drag and drop a navigation bar onto this orphaned view controller, and then manually add a back button. I want to handle my own back functionality and then use self.dismissViewControllerAnimated(true, completion: nil) to go back.
The problem is that this navigation bar doesn't have the same height or feel as the traditional one - the back button is way up high almost hitting the carrier/bars of service/4g/LTE area, and the title is touching the top of the screen. It's too high.
If I manually move it down, it's height doesn't occupy the whole area and there is this weird white strip.
Any ideas on how I can drag&drop my own navigation bar and get it to look like the ones typically done when you have a navigation controller?
Thanks!

Can you wrap your controller in a navigation controller, and present the nav controller modally:
UINavigationController *modalNavcontroller = [[UINavigationController alloc] initWithRootViewController:youController];
[self presentViewController:mdalNavcontroller animated:YES completion:nil];

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.

How do you change views from a Tab Bar Controller

I am developing an app that consists of a Tab Bar Controller that points to 3 view controllers (all with tabs). In one of these tab views I've made a button and I want it to open a new view (without a tab at the bottom). This new view would need a navigation bar with a back button to return to the previous view, so I was thinking I need to create a navigation controller?
Essentially this is what I'm trying to do (I apologize for the poorly drawn diagram).
How can I get this new view (entirely independent of the tab bar controller) to display programatically? Would this require a navigation controller?
You are describing a presented view controller. Call presentViewController:animated:completion:.
I very frequently do this with a navigation bar and a Back or Done button, just as you describe. But it's not a navigation controller or navigation interface; it's just a convenient way of showing the user how to get back.
For example, this is a presented view in one of my apps. The top is a navigation bar, and the cancel button gets us back (call dismissViewController...). The rest is a scrolling view (a UICollectionView) of buttons.
[myTabBar setSelectedIndex:1]
You may have to access the tabBar like self.tabBarController so… [self.tabBarController setSelectedIndex:1];
1 is index 1 in the tabbar's stack (this is like tapping a tabBar button manually)

iOS Push Navigation Controller, without a bar on the second view

I have an iOS App, designed within a UINavigationController. One of the pushed view controllers, however, needs a full screen view, without the navigation bar on the top. (to get back, there is just a small, circular button). However, any method I've tried of 'hiding' the navigation bar (navigationCtl.navigationBar.hidden=TRUE) leaves me with ugly artifacts - calling that before the view is pushed (in viewDidLoad or viewWillAppear) causes the previous view controllers bar to flash white just as the slide left animation starts. Similarly, calling it in viewDidAppear leaves a white bar at the top of the second view, along with several subviews pushed down, out of the way. Is there any way I can just have the new view slide over as it usually does, but when it comes over, there's simply no navigation bar up top?
Please note, to help Google, essentially the question here is:
How to animate between two UIViewControllers, when one has a navigation bar at the top, and the other one does not have a navigation bar at the top. So, how to navigate from a UIViewController with a navbar to one without a navbar - avoiding the horrible flickering.
The amazing answer is given below by Ev ... awesome.
give this a spin and see how it works for you.
in the destination view controller in viewWillAppear
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
It actually has a cool effect and can be useful. in the viewWillAppear everything happens before the view is displayed so it takes away the strange artifacts.
be well

Problem with "Presenting a controller modally within a nav controller within a tab bar controller"

My app has two distincts modes. There's a tab bar controller in the app delegate. There are two tabs, both using subclassed view controllers. The two view controllers essentially contain a nav controller each. The nav controllers have their root view controller, and normally when changing screens, I just push and pop controllers of the respective nav controller. This has the (normal) effect that the bottom tab bar is always visible, all great and sound.
This one time I'd like to present a screen modally however, so that the user can't do anything else than confirm or cancel the page using two buttons, ie I want to hide also the bottom tab bar. This would be a case for presenting the view modally I thought, but the view is presented within the nav controller bounds it seems, so the bottom tab bar is still visible, and this causes confusion in navigation the app. I'm not sure how it's possible that the modally presented view is not hiding the tab bar. Most of the questions around here seem to have the problem the other way around (wanting to (incorrectly) present a modal view and leave the tab bar visible).
These are my attempts:
[self presentModalViewController:controller animated:YES]; // inside tab bar controller :-(
[self.tabBarController presentModalViewController:controller animated:YES]; // nothing is displayed. The new controller is instantly deallocated.
[self.navigationController presentModalViewController:controller animated:YES]; // inside tab bar controller :-(
Investigating this, the self.tabBarController is actually nil. There seems to be no link back to the tab bar controller... I guess, to display modally on top of the tab bar, I need to get a link to that tab bar controller?
I seem to have found a solution, I'm not sure it's kosher, because somehow I wasn't able to use the self.tabBarController pointer of the view controller in which I start the view controller call.
What I did was reach for the app delegate, the app delegate having the tab bar controller defined as a public property. I could use that tab bar controller property to modally display my view controller over everything on the screen.

Hidden UINavigationController inside UITabBarController

I have an application with 5 UIViewControllers each inside a corresponding UINavigationController, all tucked inside a UITabBarController that displays 5 tabs at the bottom of the screen.
I want to display another UIViewController (inside a UINavigationController) when a dialog button is pressed.
This view should only be loaded and unloaded programatically; i.e. it should not appear in the tab bar. However, I want the tab bar to be visible always.
If I add the [UINavigationController view] to [self window] the UITabBar is covered. If I add it to any other layer, the UINavigationController adds on the compensation it has for the status bar so appears further down than expected.
A solution would be to have the 6th UINavigationController added to the UITabBar with the others, but with its tabBarItem hidden. Then I can show it and hide it using the tabBars selectedIndex property.
Accessing the tabBarItem through the UIViewController shows no obvious way of doing this.
#wisequark, I think you completely misunderstood and you have almost rewritten the architecture of my application. However I have a separate navigation controller for each view as they are mutually exclusive and there is no concept of "drilling down".
#Kendall, This is what I expect I will have to do - have the modal view appear with a hide button to bring back the normal interface. But it would be nice to keep the tab bar always visible, so I was just wondering if anyone knew of a way.
It sounds as though you have a mess on your hands. A UINavigationController is a distinct object that is very different from a UITabBarController. In general, your application should have a tab controller, one of who's tab's loads a UINavigationController which in turn loads it's views - not that both maintain management over the different views. It is also improper to refer to the display of a UIViewController as such an object doesn't have a visual representation. In the case of a UINavigationController, the navigation controller object is responsible for displaying a navigation bar and a table view (in the most common case) and for managing the display of all the views in the navigation hierarchy. It itself has no corresponding representation on screen. Similarly, a UITabBarController presents a tab bar and is responsible for the loading and unloading of the views and/or view controllers attached to the tab buttons. If we were to present this as an image, it would look something like this -
alt text http://img.skitch.com/20081112-2sqp7q4wafa34te1ga337u4k8.png
Well, it sounds like what you really want to do is present a modal view with the tab bar still visible. You could add your view as a subview of the tab bar controller's view. The tab bar's view is, oddly enough, not the tab bar itself but rather a view containing the tab bar and the selected item's view.
Alternatively, you could try calling presentModalViewController:animated: with the selected tab (i.e. [tabBarController.selectedViewController presentModalViewController:animated:]) as the receiver instead of the tab bar. I seem to recall doing this once (quite by accident) and the tab bar remained visible.
One more thought: since each of your five view controllers is a UINavigationController, you could always pushViewController:animated: onto the selected view controller, then hide the back button. Your view will just appear without animation. But you'll need to remember to pop your view controller off the stack whenever the user switches to another tab. That might take a bit more work.
The best idea I could think of would be to either push a modal navigation controller for your view (which would hide the tab bar which you do not want), or to get the tab bar controller current selected view controller (really your navigation controller for a tab) and push your new view controller on there - and then pop that view when another tab is selected with a tab bar delegate.
It seems wierd to me to push the view onto random tabs though, if the view is created from a dialog that is modal, I don't see why the view itself should not also be modal and hide tabs.

Resources