Display extra view controller without removing the tab bar - ios

My app has a menu and a UITabBarController. What I want to do is to display a view controller that belongs to my menu but not to the UITabBarController, However I don't want to remove the UITabBarController. I tried codes similar to the one below but they are removing the UITabBarController.
tabBarViewController.selectedViewController?.presentViewController(ExtraViewController, animated: true, completion: nil)

You should get UINavigationController of selected ViewController and then push view you want to present. Otherwise you are presenting modal view controller with presentViewController witch hides your UITabBarController view.
Im not at my computer right now, and cant post any code, but hope this helps.

Best way to do it is to use UINavigationController. You can create new one programmatically and put your menu controller as root.
And if you put this UINavigationController as one of views in UITabBarController then you can preform a code like:
[self.navigationController pushViewController:ExtraViewController animated:NO];
Also you can use storyboard to create your controllers hierarchy like that:
To do that select your menu controller and go to Xcode menu>Editor>Embed in>Navigation Controller and then Xcode menu>Editor>Embed in>Tab Bar Controller.

Related

Different navigation item for each view in tab bar controller

The Problem
I'm relatively new to Swift and I'm trying to build an application that makes use of a UITabBarController.
What I'm trying to do is put a different navigation bar (or UINavigationItem) on each of the tabs in the UITabBarController.
For example, I want the UINavigationItem I set, with its bar button items, to appear on MyViewController instead of a back button to the previous view controller, such as shown on the image below.
The current layout on the Storyboard is as follows.
MyViewController on the sidebar:
What I've Tried
Someone suggested that I should embed each UIViewController (e.g. MyViewController) in a Navigation Controller. I've tried this and it doesn't work.
I've also tried to set the Top Bar to "None" in the Attributes tab of the options menu.
Thank you in advance for your help.
Here is how i did it,
UINavigationController -> UITabbarController
And then each "Tab" is in different Storyboard and every storyboard start with a "Navigation Controller". So yes every tab in different navigation controller this how you should do it.
Different storyboards because may be multiple people work on storyboard at same time.
Why TabbarController inside Navigationcontroller ?
I put the "TabbarController" inside "NavigationController" because some of the controllers i want them to be full screen, like hiding the "Tabbar" so for that i push them from main NavigationController.
//Out of context but may help you,
I have created an "Extension" of Navigation Controller to push a view controller on main navigation so that any of the tabbars (which are also inside navigation controllers) can easily use the extension to push any view controller if want to hide the tabbar.

How to make SWRevealViewController a child of another controller in swift

Hi I've a problem I tried to solve it by reading the docs but I couldn't.
I want to the tab bar controller to be the initial VC Not the SWRevealViewController.
The issue is that the slide out menu in side the app not the first vc.
So the question how to make the SWRC there?
Why could not you move your reveal view controller as a last controller in navigation queue and use your controller with "Item" menu as Sw_front? It should work.
As an alternative you can remove the whole reveal view controller from Storyboard and create it manually from your first view controller in navigation queue. And then push.
SWRevealViewController has a method called initWithRearViewController:frontViewController, and you can obtain Sw_rear and Sw_front view controllers with instantiateViewControllerWithIdentifier from Storyboard.
Then, when adding Item menu (manually) to navigation bar, you assign revealToggle: as action and your SWRevealViewController instance as target.
There are some variations of this approach, you can place your SWRevealViewController before the Navigation Controller in Storyboard and specify Navigation Controller as a Sw_front. Then you do not need to instantiate SWRevealViewController manually, but only "Item" menu.
Here could be also useful to removeGestureRecognizers from reveal view controller on viewWillAppearof intermediate view controller in navigation queue and then add back panGestureRecognizer and tapGestureRecognizer on viewWillAppear of the view controller with "Item" menu.
UPDATE
Here is the sample project of using SWRevealViewController in Swift with Tabbar.
I've just taken the sample project from http://www.appcoda.com/sidebar-menu-swift/ and adjusted a little bit.
And what I dislike about using SWRevealViewController with Storyboards is that each new ViewController to be shown, has its own Navigation Controller, but if it works for you, you can keep it.

iOS Storyboards - Re-use UIViewController

I've got the following structure setup in my Storyboard.
I've got a TabViewController (circled in red) that shows a UIViewController via one of its tabs by doing a push (circled in blue).
I want to re-use that UIViewController from the TabViewController. I'd like to 'push' it but I don't really have a navigation controller so I may end up displaying it as a modal.
However, I'm not sure how to handle navigation back to the TabViewController since in this case there's no navigation bar. Any suggestions on the best way to handle this?
EDIT
Is there a way to insert a Navigation controller when its displayed directly from the TabViewController?
Why don't you put your view hierarchy like this:
UITabBarController -> UINavigationController -> BlueViewController
This UINavigationController should be put in the viewControllers property of the UITabBarController instance. If you do this, you can push and pop as many view controller as you want and you can also hide the navigation bar if needed.
Cancel button whose action is [self dismissViewControllerAnimated:YES completion:nil];

UINavigationController shows black screen after pushing a view

I have a storyboard application with a navigation controller an two views controllers ('A', 'B').
In the Storyboard file:
Navigationcontroller is the initial view controller. view controller 'A' is connected to the Navigationcontroller as rootcontroller. View controller 'B' is in storyboard but not connected to any view controller.
when i programmatically try to push view controller 'B' onto the navigationcontroller from inside view controller 'A' with:
B *controllerB = [[B alloc] init];
[self.navigationController pushViewController:controllerB animated:YES];
all i get is a transition to a black screen.
i checked the navigationController property in view controller A at runtime and it´s not nil.
I do not instantiate the navigationController by myself, I let storyboard do the work (maybe that´s the problem). But I think it should be possible to "manually" push view controller to a navigation controller created by storyboard.
When I connect a segue from a button to 'B' in storyboard everything works fine.
Only programmatically it does not work, only shows a black screen inside the navigationcontroller.
Maybe someone could help me with this issue.
I haven't used storyboards yet so this answer is from a glance at the docs. It looks like you can't alloc/init a view controller from a storyboard. You need to use the instantiateViewControllerWithIdentifier: method of your UIStoryboard instance and then you can push the controller.
The accepted answer didn't work for me. I was already using instantiateViewControllerWithIdentifier to navigate to view controller in different storyboard. I am using xcode7.2 and Swift.
I am navigating from storyboard1, some view controller's button action.
Destination is to initial Navigation controller of Storyboard2.
Still I get black screen.
The problem was storyboard2's Navigation controller linked to 1st view controller was linked via show.
Solution:
Delete the link between Nav controller and 1st view controller. Now link it using root view controller. (Ctrl+Click on Navigation controller and drag it to the View controller and Select the option "root view controller")

uinavigation not working

My navigation controller not working.
I take a tabbar-based application now from app delegate. I want to add a navigationcontroller but it's not working.
[window addSubview:navigationController.view];
I simply make an object of uinavigation controller and synthesize it.
Actually you don't need to add navigation Controller's view in the window, if you want to add a navigation controller in tabbar controller application.
See the below screen shot, you just need to select the tabbarcontroller in the IB and then from inspector window you can select class or particular tab item. Just make then navigation controller.
Open MainWindow.xib.
Under TabBarController you will see two view controllers.
Delete both of the view controllers.
Now, from the library add two navigation controllers under TabBatController.
Now, open the inspector of the navigation controller and set its nib name and the class name.
i think this will solve your problem.
You can also go through
http://21gingerman.wordpress.com/2009/04/06/tutorial-and-sample-code-for-iphone-app-with-tab-bar-and-nav-bar/

Resources