Why tabbar is hidden on navigation? - objective-c

i have created a tab bar application,
There is a present modal view controller when button clicked in viewcontroller 1, and with navigation controller i can navigate to Viewcontroller2 from modal view
My problem is that,when i navigated to viewController2 the tab bar is hidden,how can i show the tab bar?

If you're pushing a view controller onto your navigation controller's stack, then the tab bar will stay:
[self.navigationController pushViewController:viewController2 animated:YES];
But if you're presenting it as a modal view controller then it becomes the top/front-most view (presented in full screen), thus hiding the tab bar until the view controller is dismissed:
[self presentViewController:viewController2 animated:YES completion:nil];
The point of a modal view controller is to force the user to deal with the presented view controller before doing anything else inside the app. If you need to access viewController1 in viewController2 then you could declare a property viewController1 *previousViewController in viewController2 and set viewController2.previousViewController = self; (in viewController1) before presenting the view controller. Alternatively you could try adding the view (subtracting the height of the tab bar when defining the frame) to your tab bar controller's view.

Related

Modal view controller pushed from tab view controller always returning to first tab

I have a view controller inside a tab bar controller (the view controller is item index 2). When I push a modal (camera picker) from the view controller, when it dismisses it always returns to the first view controller in the tab bar controller (item index 0). Now I COULD set the tab upon completion of dismissal, but that creates an ugly "flash effect" where it shows the first view controller for about a milisecond before going back to the right one. It's quite ugly from a design standpoint. How can I fix it?
Here's what I have now that is ugly:
[picker dismissViewControllerAnimated:NO completion:^{
UINavigationController * nav=self.navigationController;
RootTabBarController * root=(RootTabBarController *)nav.parentViewController;
[root showProfilePage]; //this calls setSelectedIndex in the tab bar controller
}];
I accidentally set SetSelectedIndex=0 in the tab bar controller view did appear.

Change Selected Index of Tab Bar Application from Modal View Controller ios7

I am presenting a modal view controller off of one my tabs in ios7. Depending on the user's action, I want to change the selected index of the tab bar controller.
I have tried
[(UITabBarController *)self.parentViewController setSelectedIndex:0];
This does not change the selectedindex of the underlying tab bar. Please let me knwo if there is another way to do this
Just do
UITabBarController *tabBarController = (UITabBarController *)self.presentingViewController;
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
[tabBarController setSelectedIndex:1];

How to hide the NavigationBar when i use SWRevealViewController embed in UINavigationController?

When i use SWRevealViewController as initial view or not embedded in UINavigationController the result is as i expected:
but when the SWRevealViewController comes from UINavigationController tee result is:
How can i avoid the NavigationBar presented in the Rear view?
Please add the following code to the viewWillAppear: method of the viewcontroller whose navigation bar you need to hide.
[super viewWillAppear:YES];
[self.navigationController.navigationBar setHidden:YES];
[self.navigationController.navigationBar.backItem setHidesBackButton:YES];
Try, this code for rear view controller
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.hidden = YES;
}
If you really need Navigation Controller on top of SWRevealViewController:
You got to hide navigation bar from navigation controller of your SWRevealViewController.
U can do this in IB (assuming you are using Storyboards):
Select Navigation Controller in your Storyboard
Open Attributes inspector
Find section "Navigation Controller", uncheck "Shows Navigation Bar"
Next, If you want navigation bard in front view controller, then attach it to separate Navigation Controller. You will have two Navigation Controllers, think on which one you want to push - it will have different effect.

hide navigationbar of uisearchdisplaycontroller when other viewcontroller is pushed

i have a uitableviewcontroller with uisearchdisplay controller. tapping on table cell pushes another view with some content and hides the navigationbar in the pushed view controller. the view controller has it's own uitoolbar, so far everything ok. the problem is that when a search result is shown and then tapping on the table cell view pushes the viewcontroller with uitoolbar with a navigation bar above it. so two bars on the pushed view. i dont want the navigation bar to be hidden. this code works if the viewcontroller is not pushed from search result
[self.navigationController setNavigationBarHidden:YES animated:YES];
what i'm missing using uisearchdisplay controller and hiding its navigation bar when other view is pushed?
I have redesigned my app. i dont use uisearchdisplay controller. instead i use uisearchbar and tableview which works perfectly.

UINavigationController without NavigationBar

I have a "landing page/view" that I dont want the navigation bar to show, so I turn it off during the viewDidAppear
navigationBarHidden = YES;
When i push a view on the stack and then move it off. the main landing page shows the nav bar then hides it which cause a flicker that I dont want.
is there a way to have the landing page be a UIView or something? When a menu item is touched the app would push a new view on top of the default landing page. It sound like it would be hard to do without having the landing page be a UINavigationController. Any thoguhts?
Try hiding the navigation bar in viewWillAppear, rather than viewDidAppear.
If you don't need to go back to the landing page, use a view controller for the landing page and present it modally from the navigation controller when the application starts.
So you do want to go back to the landing page.
It's hard to accomplish that with UINavigationController. Suppose your are going back to the landing view. While the transition, the old view should have a navigation bar, and the new view (landing page) should not have a navigation bar. UINavigationController does not allow you manually modifying the transition animation. In other words, you cannot animate hiding/unhiding the navigation bar along with push/pop animation (using viewWillAppear doesn't solve the problem).
So what would I do, if I really, really need this?
I would have a rootViewController (of UIViewController), whose view is the only subview of your application window. When your application starts, rootViewController add the landing view as a subview of its view. When the user selects an item there, you create an UINavigationController with the corresponding view controller as its root view controller.
And, using CATransition animation with type of kCATransitionPush and subtype of kCATransitionFromRight, you add the view of the navigation controller as a subview of rootViewController's view.
Then you need a 'back' button for the first view of the navigation controller. In all view controllers that are the first level view controllers of the navigation controller, create a bar button item with a text 'Back', and add it to their navigationItem.leftBarButton property. Set a target-action (probably to the rootViewController) pair for the button.
When the action message fires, use CATransition animation (now with kCATransitionFromLeft subtype), to remove the current navigation controller's view from rootViewController's view.
The transition may not look as perfect as the native UINavigationController, but I believe this is the best you could get.
Actually the way to do this is to implement UINavigationController's delegate method navigationController:willShowViewController:animated. This method is where you should handle hiding and showing your navigation bar so the animation will occur during the push/pop animation.
I came across a method that is simple and works well for me, and is not given here yet. I assume you have a view controller for the main landing page and it is set as root view controller of the navigation controller. Then you should hide/show the navigation bar in the viewWillAppear and viewWillDisappear methods of the main landing page controller:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
Source:
http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/