Show / Hide tab bar - iphone

Everyone
I have a problem and I have been searching the solution but could not find any. I am working on a tab bar based app. Problem is that I want to hide tab bar at first screen and then show it on all other screens that are being displayed after first screen.
Can anyone please give me the best solution for this problem?
Actual scenario is that I have a screen that is login screen. Now i dont want to show tab bar here as tab bar will be displayed only if the user is signed in. When user logs in, I want the tab bar to be displayed showing its contents.
Best Regards

If you have your Tab Bar Controller as your rootController, you can use rootController.selectedIndex =0 for selecting 1st Tab bar Item, and rootController.selectedIndex =1; and so forth.
As soon as that particular view loads, you can load the other views in an array, and then add it to the rootController.selectedIndex and reloadInputViews with animation.
Edit: (as per the comments)
So you have a tab bar controller, and you want to show the introduction and the login screen while starting the App. If login is successful, you want to present the tab bar controller ! This can be done with ModalViewControllers
In the ViewDidLoad of the view that loads up first, (it's your first tab by default), add
//Declare Introduction Screen//
IntroductionController *introductionController = [[IntroductionController alloc] initWithNibName:#"IntroductionController" bundle:[NSBundle mainBundle]];
//Give a navigation screen for your introduction screen and set it to introduction screen
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:introductionController];
navController.title = #"Introduction";
navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:navController animated:NO];
Now your introduction screen would load as soon as your first tab bar loads. But the loading is instantaneous, so it's not visible to the user's eye. Now reference your Login View Controller like #class LoginController and create an object LoginViewController *lvc;, and synthesize it. Now declare LoginButton and in the IBAction
-(IBAction) loginAction: (id) sender{
NSLog(#"I clicked Login");
if (self.lvc ==nil){
self.lvc = [[LoginController alloc] init ];
}
lvc.title = #"Login";
[self.navigationController pushViewController: self.lvc animated:YES];
}
And in the LoginViewController, if Login is successful, just do
[self dismissModalViewControllerAnimated:YES];

create an outlet for the uitabbar, then declare it hidden in the first screen, then create a new void, NOT SENT SO IT DOESNT WORK in the first screen, make it say, lets say, hide. And inside hide, put code saying your uitabbar.hidden = YES; then, to make it work in the other view, write this in the viewDidLoad:
[(//first view*)[UIApplication sharedApplication].delegate //the void, in this case, hide];

Related

When going back from Flip Side of Tab Bar, Tab Bar Doesn't Load. iOS

So I have a tab bar app with three tabs. In the second tab, I have a button that loads another view in which two text fields pass their values into two labels in the original tab view. When I click the button, enter my values, and click the set button to go back to the original view, the labels are changed, but the tab bar doesn't load. How do I load the tab bar after switching from a different view?
Code for when the button in the original tab bar view is pressed
TeamNameViewController *fvc = [self.storyboard instantiateViewControllerWithIdentifier:#"99"];
fvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:fvc animated:YES completion:nil];
Code to go back to tab bar
SecondViewController *tempView = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondViewControllerSB"];
tempView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:tempView animated:YES completion:nil];
The short answer is: You don't.
presentViewCntroller:animated:completion presents the target view controller modally. The other views still exist and you don't need to instantiate them again, you need to dismiss the modal view controller.
You need to call dismissViewController:animated:completion on the presenting view controller (that is the view controller that calls presentViewController:animated:completion is responsible).

Set focus to UITabBarItem

I have a UITabBarController with several tab bar items in it. The first tab bar item has a view called A and it has a button called Click . When i click on that button the view will navigate to another view. (Since this tab has a UINavigationController the view will get a Back button).
Now this view will have a button, where when i click on it, i should navigate to the 2nd TabItem. (Meaning the UITabBarItem should be set focus, and there should not be a Back button (as in a navigation controller))
Note :
When the user clicks on the button, i used the following code to navigate to the other view of another UITabBarItem. Then the 2nd tab bar item is not set focused, and the back button from the navigation controller is also seen.
SelectSiteViewController *siteViewController =
[[SelectSiteViewController alloc] initWithNibName:#"SelectSiteViewController"
bundle:nil];
[self.navigationController pushViewController:siteViewController
animated:YES];
Hope i made my question clear. How can i code this?
As I understand, you want to remove the current view controller from the navigation task and select the second tab in the tab bar controller.
UINavigationController *navigationController = self.navigationController;
[navigationController popToRootViewControllerAnimated:NO];
[navigationController.tabBarController setSelectedIndex:1];
[myTabBarController setSelectedIndex:1];

problem with tab bar, not displaying the tab bar upon navigating to that page

In my test project I have some 5 tabs on click of a tab it will go to that corresponding class, on click of back in that screen I will come back to my home page but with out the tab bar.. earlier what 5 tabs were there those are not coming ...
following code I am using under back button
where DataEntry is the class to where i need to navigate
- (void) back_Clicked:(id)sender
{
DataEntry *avController;
UINavigationController *addNavigationController;
if(avController == nil)
avController = [[DataEntry alloc] initWithTabBar];
if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];
[self. navigationController presentModalViewController:addNavigationController animated:YES];
}
is I have to add that navigation controller to the tab view? how can I get the tab bar on click of back can any one help me ,thanx in advance
As I understand this, you must already be pushing this view controller either via navigation controller or modally. So the idea would be to simply dismiss it right?
If you have used [self.navigationController pushViewController:animated:] then just do [self.navigationController popViewControllerAnimated:YES]; . This should take you back to the earlier view controller.
If you have presented this modally like you have done here, you should do [self.navigationController dismissModalViewControllerAnimated:YES];.
If you need to return back from a view to the previous view using a back button inside a tab view , i would recommend using a navigation controller inside the view for each tab where you require this functionality. Trying to implement a custom back button without using the navigation controller, in my opinion, is only making things tough for yourself.
If you only want one view to be displayed when you tap on a tab bar button then an ordinary view controller inside the tab bar view should suffice.
The tab bar shouldnt be disappearing altogether unless its been implemented incorrectly.

iPhone - how do I add a navigation controller to a view?

I currently have an application that does the the following:
S: Loads a view as a login screen to start with.
a: If login is successful I add a terms and conditions screen as a subview
b: If not successful I add a sign up form as a subview
F: Then I load the main part of my app on success of either of the a or b which is the part of the app where there is a navigation controller and a tab bar controller. This is set up in MainWindow.xib
S, a and b also have Nav bars but no navigation controllers as I didn't think I would need navigation control on the login screens.
However it turns out I do, I want to be able to have back navigation from both a and b to the initial login screen.
I have tried several ways of doing this including trying the following answers:
How to add navigation controller in View Based Application in iPhone?
How do you properly set up a secondary view to support a navigation Controller on the iPhone?
how to add navigation controller programatically?
But none of them work for me, they display the new Navigation controller over the login screen and dont load the a or b screens.
I'm guessing this is because I am adding them as subviews to my loginView and this is not the correct way to do this? My code is as follows:
if(self.tcSubViewController == nil){
TCSubViewController *_tcSubViewController = [[TCSubViewController alloc] initWithNibName:#"T&CView" bundle:[NSBundle mainBundle]];
self.tcSubViewController = _tcSubViewController;
[_tcSubViewController release];
}
[self.view addSubview:[tcSubViewController view]];
I'm guessing there's a fundamental flaw in the way my Login flows? I should be able to completely remove the LoginView and then display the Terms and conditions view without having to add it as subview, shouldn't I?
You need to dismiss the navigation controller to go back to.
To dismiss modal view:
1.Easy way: In your modal view in some method that you call to dismiss just add:
[self.navigationController dismissModalViewControllerAnimated:YES];
2.More complex way: Implement and delegate protocol on your modal view and make the view controller that presents the modal view the delegate of it. And in the delegate method dismiss the modal view. I do this way when I need to send data from modal view to the controller that present it.
Reference to this post
Navigation controller philosophy is that you add only navigationController.view as UIWindow subview and it wil manage the rest by itself. You only need to push/pop viewControllers and their corresponding views will be added/removed from screen automatically.
sample code from my current application:
HomeController *homeController = [[[HomeController alloc] init] autorelease];
self.controller = [[[UINavigationController alloc] initWithRootViewController:homeController] autorelease];
self.controller.navigationBarHidden = YES;
[self.window addSubview:self.controller.view];
[self.window makeKeyAndVisible];
and then to push next view you just add next controller:
[self.navigationController pushViewController:newController animated:YES];

How to switch tabs and pushViewController at the same time?

I have two tabs in my app, the left tab is a normal UIViewController, right tab is a navigation controller with a table view inside it. I'd like to allow the user to press a button on the left tab and jump to a specific detail view that belongs to a specific row in the table view on the right tab.
In the table view itself I have no problems displaying a specific detail view eg:
[self.navigationController pushViewController:theView animated:YES];
and I can also jump tabs using
self.tabBarController.selectedIndex = 1; // 1= right tab
but I cant figure out how to do both. I've tried
self.tabBarController.selectedIndex = 1; // 1= right tab
// alloc and init theView here
[self.navigationController pushViewController:theView animated:YES];
but that doesnt work.
EDIT:
when I try the above code it just switches tab but doesnt push the view.
I also tried what criscokid suggested but nothing happens at all.
EDIT 2:
Trying to explain whats on each tab:
Root (Tab Bar Controller)
|
--(Left Tab)-- UIViewController (I want to go from here...)
|
--(Right Tab)---UINavigationController
|
---UITableViewController
|
----UIViewController (...to here)
^ specific view with data from specific row
in table view (that is 'theView' from above)
For me the correct way was:
UINavigationController * navigationController = (UINavigationController *) [[self tabBarController] selectedViewController];
[navigationController pushViewController:viewController animated:YES];
criscokid's answer has one redundant call to navigationController.
That's because your selectedViewController is actually a UINavigationViewController.
If you are switching the tab bar and pushing the ViewController onto the navigation controller stack in the same method, you wouldn't want to use self.navigationController. If I understand correctly you want to add it to a navigationController on the right tab. I believe you would want to use:
[[[[self tabBarController] selectedViewController] navigationController] pushViewController:theView animated:YES];