Set focus to UITabBarItem - iphone

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];

Related

Properly manage nav bar and tab bar

The figure shows my storyboard, with segues as directed.
In the tabBar's landing viewcontroller (i.e. I), both tabBar and navBar are visible which is desired. However, if a segue is performed (from I) to go to another viewcontroller (here, II), I want only the navBar. I am able to hide the tabBar by using
self.tabBarController?.tabBar.isHidden = true
Next, I am able to achieve the desired result by adding navigation controller at the beginning as shown below.
This configuration will add a navbar to the viewcontrollers ahead (like splash screen) so I will have to hide the navbar in those viewcontrollers.
Is there other method that does not require to hide the bar(s) and achieve the desired effect?
You should go with your first approach. Tab bar controller have default property to hide bottom bar. See below sample code.
ViewController *viewController = [[ViewController alloc] init];
viewController.hidesBottomBarWhenPushed = YES; // This property needs to be set before pushing viewController to the navigationController's stack.
[self.navigationController pushViewController:viewController animated:YES];
This will hide your tab bar while pushing to any child controllers.
EDIT
You can also set hidesBottomBarwhenpushed from storyboard for your tabbar controller so you don’t have to write down any code.

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).

Navigation Issue with UITableView

How do I navigate back to the previous page with a UITableViewController. I tried to show a navigation bar with navigation button at the top of the screen, but the navigation bar will not show. I know that you have to give the previous view a title but when I go to do that it does not show anything. Also, since it is a UITableViewController I am not able to drop a navigation bar and add a button to the main view. All I would like to do is display my lists and have the option to navigate back to the previous list with a single button in the upper left corner.
The problem you having with the NavigationController is that your tableViewController is not in the NavigationController hierarchy. Want you want to do this when adding the tableViewController:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourTableViewController];
Then you can do this to add yourTableViewController:
[self.view addSubview:navigationController.view];
If you don't want the navigationBar to appear on the tableViewController just use:
self.navigationController.navigationBarHidden = YES;
in yourTableViewController viewWillAppear method.
When your going to add the view after the tableView you just use:
[self.navigationController pushViewController:someViewController animated:YES];
It's not enough to give the child view a title. You need to give the child view's navigation item a title before you present it. For example, in the parent view, before you push the the view to the navigation stack, do something like this...
[MyChildView.MyNavigationItem setTitle:#"A cool Title"];
For the navigation you are trying to achieve you should be using a UINavigationController. It already has the functionality you describe with the navigation bar and back button built into it.
To move to the next screen (which can be a UITableViewController) you use pushViewController:animated: and to move to the previous screen you use popViewControllerAnimated: (although the built in back button will do this for you).
I suggest reading the UINavigationController class documentation if you are not already familiar with it.

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.

tabBarController navigation problem/question

I have a simple tabBarController application where the user can navigate around 3 views.
In one of the views I have a UIButton that when touched moves the user to a fourth view. the problem is that the new view doesn't have the tab bar navigation visible.
what do I need to do to the fourth view to have it also use the tabBarController feature set.
thanks for any help
here's the code that transitions to the fourth view when a UIButton is touched:
-(IBAction) nextQuestion {
Question2 *q2 = [[Question2 alloc] initWithNibName:#"Question2" bundle:nil];
q2.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:q2 animated:YES];
[q2 release];
}
A modal view controller always takes up the entire screen. Its purpose is to provide a modal interface that does not let the user interact with other parts of the UI until they dismiss the modal view.
To display another view inside a tab, you could make the root controller of that tab a navigation controller. A button tap would then push the Question 2 controller on the nav controller's stack.