TabBar is not visible on navigating into another UIViewController - ios

I am navigating from TabBarController to another UIViewController.
aViewController.title = #"Product Name";
[self.tabBarController.navigationController pushViewController:aViewController animated:YES];
after navigating from the tabbar is not visible.
So change code
[self.navigationController pushViewController:aViewController animated:YES];
TabBar is visible but < Back button is not visible.
How to have tabbar and the default back button after navigating from tabbar?

I've just created a test project for this issue and you will see that it's working as expected.
https://github.com/Pei116/TabTest-iOS

Related

UITabBar View not opening - selected index

I have a login screen after which home screen is shown. In home screen ,there are four buttons a,b,c,d. On pressing each button, say view a,b,c,d should appear related to view controller a,b,c,d. All these views are embedded in a UITabBar controller. The problem now is when I use the code
[self.tabBarController setSelectedIndex:2];
nothing happens and no view appears. How do i open the view using selected index method or any other method?
Thank You
Found the answer finally. Instead of
[self.tabBarController setSelectedIndex:2];
Use
UITabBarController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"IdentifierFromStoryboard"];
[self.navigationController pushViewController:controller animated:NO];
[controller setSelectedIndex:2];
This would work fine.

xcode tab bar controller change selected item with code

Firstly,I'm using Xcode 6 and Objective-c. I want to change tab bar screen with button or automatically with code how can i do this.Another question may i do this different view not a item of tab bar controller.
- (IBAction)backButton:(id)sender
{
ProfileSide *vc = (ProfileSide *)[[self.tabBarController viewControllers]objectAtIndex:1];
[vc.view setNeedsDisplay];
[self.tabBarController setSelectedViewController:vc];
}
I tried this code part but not working. ProfileSide name of the class 3rd item tab bar controller.
ProfileSide *vc1 = [self.storyboard instantiateViewControllerWithIdentifier:#"meScreen"];
[self presentViewController:vc1 animated:YES completion:nil];
Also have got this code part but when i use this one tab bar get disappear.
[self.tabBarController setSelectedIndex:yourIndex];

tab does not switch programmatically for a tabBar inside a navigation controller

My app starts with a navigation controller which opens a UIViewController. This screen works as a login page.
On login, I open a UITabBarController like this:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
UITabBarController *obj=[storyboard instantiateViewControllerWithIdentifier:#"MainTab"];
self.navigationController.navigationBarHidden=YES;
[self.navigationController pushViewController:obj animated:YES];
Inside my tab bar controller, I want when clicking a button to switch tab programmatically. I tried the following 3, neither of them worked. Code is place inside a method, which is invoked when the button is clicked.
For the first 2, the tab didn't change - still my initial tab is highlighted and the correct view controller is not shown. For the last one, app crashes.
1st :
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
2nd :
[self.parentViewController.tabBarController setSelectedIndex:1];
3rd:
UITabBarController *MyTabController = (UITabBarController *)((AppDelegate*) [[UIApplication sharedApplication] delegate]).window.rootViewController;
[MyTabController setSelectedIndex:1];
What am I missing?
for a tabBar inside a navigation controller...What am I missing?
One thing you're missing is the order of containment that's allowed for view controllers. Specifically, you can put a navigation controller inside a tab controller, but not the other way around.

Pushing a UITableViewController from a tabBarController embedded view doesn't remove tab bar?

I have a tab bar controller with 4 tabs and each tab is their own UINavigationController, which is how you're supposed to nest tab bar and navigation controller's together. The initial tab is a TableViewController and works/appears the way that it should. From the tableVC I can push standard view controller's onto the navigation controller with:
[self.navigationController pushViewController:VC animated:YES];
and it works properly.
If I attempt to push another TableViewController onto the navigation with the same method it works the same way, but the initial tab bar does not get pushed off screen like it should, it just stays in place.
Why would the tab bar stay on screen even though I am pushing a new VC onto the navigation?
I have tested with multiple instances of different TableVC's and it only happens with a table view controller.
Here is the code I'm using:
- (void)pushTableVC
{
TestTableVC *tableVC = [[TestTableVC alloc] init];
[self.navigationController pushViewController:tableVC animated:YES];
}
This will push the new table view onto the stack, but the tab bar from the parent VC stays in place and does not get pushed off screen like it should.
You should call the method setHidesBottomBarWhenPushed: on the view controller you are pushing to correctly hide the tab bar.
UIViewController *viewController = [[UIViewController alloc] init];
[viewController setHidesBottomBarWhenPushed:YES];
[[self navigationController] pushViewController:viewController animated:YES];
When you use a UITabBarController, the tab bar always stays on screen, even as you push additional view controllers onto an embedded UINavigationController. You will see this in any app that has a UITabBarController implemented, unless they implement custom behavior to change this.
The UINavigationController contains everything above the UITabBar, but does not contain the UITabBar itself, so it would not be able to push it offscreen.

how to go to tab bar controller after clicking the respective button

I have structure of project as shown below.
On the left side I have MainViewController. There I have two buttons as English and Arabic. What I want to do is when I click English, I want to go English tab bar controller (HomeViewController).
Hence what I wrote is
- (IBAction)langEnglish:(id)sender {
HomeViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:#"enghome"];
[self.navigationController pushViewController:secondView animated:YES];
}
This is working perfectly, but I don't see tab bar.
Tab bar is missing from this.
Any idea what is going wrong?
Basically what I have is view controller as main controller and upon clicking button on this controller, tab view controller should get open...
Go to your main storyboard and select your main view controller. On top select Editor->Embed in->navigation bar.
EDIT: If this does not work push to your tab bar and use this code:
self.tabBarController.selectedIndex = 1;
What I did is as below
- (IBAction)langEnglish:(id)sender {
EngTabViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:#"engtab"];
[self.navigationController pushViewController:secondView animated:YES];
}
EngTabViewController is the UITabBarController and I assigned id to tab bar controller... this works like charm...
Means instead of viewcontorller, I used tabbarcontroller...
You shouldn't push a UITabBarController on a UINavigationController. Set it as the window's root view controller instead and the tab bar should be displayed as expected.

Resources