Need to hide bottom bar in tab bar navigation based application - iphone

I'm having problem in Tabbar-Navigation based application. I have a tab bar with 3 tab bar button items.
Each Tab bar item, I need to show the Navigation controller's view. When I click on the first button, I need to show Navigation controller's root view.
I need that when navigation controller's view is pushed, then in one view I need to show tab bar. When second view is pushed, I need to hide tab bar. When third view is pushed, I need to show tab bar again. It should also work when the view is popped up.
In Navigation controller's root view (Main view), I need to show the tab bar at bottom. But a new view (first view) is pushed then I need to hide the tab bar. Then I have set the property hidesBottomBarWhenPushed to YES.
FirstViewController *firstController = [[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
firstController. hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:firstController animated:YES];
It works fine with the first view.
But the problem is when I push a new view (Second view) , tab bar is not shown even if I set the property:
SecondViewController *secondController = [[SecondViewController alloc]initWithNibName:#"SecondViewController" bundle:nil];
secondController. hidesBottomBarWhenPushed = NO;
[self.navigationController secondController animated:YES];

Let me know if this works.
FirstViewController *firstController = [[FirstViewController alloc]initWithNibName:#"FirstViewController" bundle:nil];
//firstController. hidesBottomBarWhenPushed = YES;
[self.navigationController presentViewController:firstController animated:YES];

Related

UIViewController Transition from right to left

I am opening second view controller on button click from fist viewController,but its animating from bottom.I want to open it in right to left.
You may be presenting the second view controller on first view button tap.
The view transition from right to left will work when you do pushing a second view.
For enable pushing the second view, at first your first view should be inside navigation controller.
If your first view is already inside a navigation controller then do the following for pushing second view:
Case 1: If your are using storyboard and First view is already embedded in Navigation controller
set storyboardID for the second view controller in storyboard (Eg. here storyboardID is same as the class name)
Do this code on your button tap of first view:
SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
[self.navigationController pushViewController:secondViewController animates:YES];
Case 2: If you are using storyboard but First view controller is not embedded in Navigation Controller:
1. Embed the First view in Navigarion controller
1.1. Open storyboard file and select the First View Controller
1.2. Goto Editor->Embed In-> Navigation Controller.
Then do the step Case:1's 2nd step.
Case 3: If you are using XIB files and first view is not in navigation controller.
1. For loading first view in AppDelegate.m application:didFnishLoading: method do as follows:
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = navigationController;
Then for pushing second view on first view button do as follows:
SecondViewController *secondViewController = [[FirstViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:secondViewController animates:YES];
If this is not helpful, then just post what you did exactly then exact solution can be given. Because what approach you are using to load view is not mentioned in your question.
Use
[self pushViewController:yourViewController animated:YES];
instead of
[self presentViewController:yourViewController animated:YES completion:nil];
The first piece of code pushes the second view controller in the screen from right to left.
The second line of code, which is what you have probably written in your app presents the view controller modally, meaning from bottom to top.

Want to create logout button in tabbar

I have created an application that have 9 screen and I have added tabbar in it which contain 4 baritem.
Now I have two problems -
1 => My last baritem is logout button, I don't want to display view controller for it, simply when user click this button then alertview should pop up and ask for logout and if user says yes then it will logout.
2=> How to display tabbar in that view controller that does not added in tabbar, because I have 9 screen and only 4 screen display in tabbar.
UPDATE
I said that I have 9 view controller in my app
like...
firstViewController
secondViewController
thirdViewController
fourViewController
|
|
ninthViewController
But my tabbar have only four view controller in baritem which are -
firstViewController
secondViewController
thirdViewController
fourViewController
Now, my other view controller does not display tabbar.
I dont know this is right way or not but you can do it like this...
first read this question that show how to display login and come back to home.
Now add this code in didFinishLaunchingWithOptions method
UIViewController * logoutVC =[[UIViewController alloc] init];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:firstView, secondView, thirdView,logoutVC, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
[self.window addSubview:self.tabController.view];
And implement this delegate method of tabbar
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
//select the index where your logout button is
if ([tabBarController selectedIndex] == 3) {
NSLog(#"logout");
self.tabController.selectedViewController = fistView; //firstview is your home screen
//LOGOUT
LoginViewController * vc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
vc.delegate = self;
[self.tabController presentModalViewController:vc animated:NO];
}
}
Your first question:
Don't do this, it's an abuse of tab bar controller. Each item on the tab bar controller should be a different view in your app, not an action. Find an appropriate place for a logout action button.
Your second question:
There are several ways to show a view controller that isn't one of the main VCs for the tab bar controller. It could be reached by:
being shown as a modal screen
as a popover
Update
To show a 'secondary' view controller that isn't a main VC of the tab bar, but still have the tab bar visible, you can present that secondary VC as a sub-viewcontroller of a main tab bar VC. In other words, present the view of your secondary VC as a subview of a main VC view.

UINavigationController navigationbar visibility set not works

I'm trying to add some navigation controller in my app, it's sth likes:
in my index page view controller, I try to initialize the navigation controller like this:
-(void)viewDidLoad{
...
//allocate a navigation controller.
myNavigationController = [[UINavigationController alloc]init];
myNavigationController.delegate = self;
myNavigationController.navigationBar.hidden = YES;
[self.view addSubview:myNavigationController.view];
[myNavigationController pushViewController:tabViewController animated:YES];
[self presentModalViewController:myNavigationController animated:YES];
}
Here, index page view controller is the root view controller of my app, it's just a common UIViewController here.
[myNavigationController pushViewController:tabViewController animated:YES];
The tabViewController here I've pushed into the navigation controller is a custom tabview controller which makes use of a container view to hold the tab button and also holds an navigation controller for tab switching.
The problem here is:
myNavigationController.navigationBar.hidden = YES;
since I've make the navigation bar invisible, it doesn't show when my custom view controller shows, but when I'd like to switch to some other view controller with the navigation controller and I also want the navigation bar visible:
myNavigationController.navigationBar.hidden = NO;
MyViewController *toSwitchNC = [[MyViewController alloc]init];
[myNavigationController pushViewController:toSwitchNC animated:YES];
The navigation bar would never show any more. I've also tried to put:
self.navigationController.navigationBar.hidden = NO
in MyViewController's viewDidLoad, ViewDidAppear or even in the navigation controller's delegate method, it didn't show the navigation bar neither.
So what's wrong with it? Why I initialized the navigation bar to be invisible at first, it will never show again even I set the hidden flag to be false?
Okay, I've got this fixed by removing the navigation controller container in my index page view controller. This might be a stupid question, since apple've formally stated in the developer document that the navigation view controller should be place as root as possible in the view stack. Since IOS is a closed system, who knows WTH is going on under-beneath except Apple.

When loading view tab-bar not displayed - noob question

I Have a TabView control, and when the user clicks on the tab item, the view will load.
When the view is loaded, there is a button on the view, and when i click on the button, another view gets loaded, i used the following code to load the view:
NextView *next = [[NextView alloc]initWithNibName:nil bundle:nil];
[self presentModalViewController:next animated:NO];
But when the view loads, the tab bar items are not displayed. It loads on top of the tab bar items. how can i make the view pop out with the tab bar items ?
NextView *next = [[NextView alloc]initWithNibName:#"yourNibName" bundle:nil];
[self presentModalViewController:next animated:YES];
if you are using presentModalViewController then you can't display the tabBar instead you can use pushViewController

Is it possible use UINavigationController but hide its navigation bar (replace it with customized toolbar) and go back button

I hope to switch between 2 UIViewController using UINavigationController. (AUIViewController, BUIViewController relate to UIView AView,BView)
AView has an UIButton, BView has an UIButton also.
If I press the button on AView, it will push BViewController and display BView.
If I press the button on BView, BViewController will pop and go back AUIViewController.
I hope to use UINavigationController's navigation function but hide its 'go back' bar and navigation bar, only use 2 buttons to tell UINaviationController what it needs to do.
Is it possible?
to hide UINavigationController's navigation bar:
[self.navigationController setNavigationBarHidden:YES];
To push a view controller from a button:
- (void)pushNextViewController {
NextViewController *page = [[NextViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:page animated:YES];
}
To pop a view controller back one:
- (void)popToLastViewController {
[self.navigationController popViewControllerAnimated:YES];
}
You can hide it in interface builder too:
Select the nav controller object
In the 4th tab on the right, under 'navigation controller', deselect 'shows navigation bar'