Hide tab bar item and aligning other tab items - iphone

In my app, i have 4 tab bar items. Iam adding these 4 tab bar items in XIB file.
Initially i have to show 3 tab bar items and after sync i have to show 4th tab bar item in my app. So for this, i am hiding 4th Tab bar item using following code.
[[[self.tabBarController.tabBar subviews] objectAtIndex:03 setHidden:YES];
The tab item is hiding but i am having blank space in place of the hidden item. Is there any chance to align other 3 items in full tab bar. The thing is i dont want to show blank space or empty space in tab bar.
Thanks
Jithen

If you want to get the items of the tabBar rearranged you have to remove the controller from the controllers list, not hide it. You can use this code to achieve this:
NSMutableArray *controllers = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[controllers removeObjectAtIndex:3];
[self.tabBarController setViewControllers:controllers animated:YES];

Related

Hide item in TabBarController [xcode6/swift]

I have a TabBarController that is linked to 4 ViewControllers, so the tab bar displays 4 items, but I only want to display 3 items.
How to I hide the other tab bar item?
I want that the ViewController that is no displayed on the tab bar also displays the tab bar.
Here is the story board:
And here is the app on the simulator:
I want the "Notificaciones" item to be hidden (it is the initial view that is displayed)
Thanks!
You can remove the UITabBarItem with the following code:
NSMutableArray *tabBarViewControllers = [NSMutableArray arrayWithArray:self.tabBarController.viewControllers];
[tabBarViewControllers removeObjectAtIndex:0];
[self.tabBarController setViewControllers: tabBarViewControllers animated:YES];
It looks like the way you have this setup right now, that once you select one of the other views, you will not be able to return to the Notificaciones view without reloading the whole UITabBarViewController.

how to add a uitab bar controller with non of the tab get selected?

I have added an UITabBarController. My requirement is to display a view with tab bar controller. but that view is not part of the tab bar items. For example my tab bar contains 3 tabs
contacts
camera
history
Generally if we add tabbar controller contacts will be get selected and that view will be displayed automatically. but i don't want in that way...
i used [tabBarcontroller setSelectedViewController=nil];
i am able to get a tab bat with non of the tab get selected. but when i am trying to select a tab item it's not working.. I think i set the selectedViewController to nil. is there any other way to achieve my requirements...?
please explain your answer clearly.. i am new to iphone app development..
Present a view controller which is not a part of your tab bar controller and put a tab bar image/buttons at the bottom of it which resembles your tab bar. When you receive a button pressed message from within that view controller, show that tab on screen.

ios5 storyboard add right button to nav bar

So i started to experiment with storyboard.
so my storyboard is as follow
nav controller -> tableviewcontroller -> tabBarController -> tableViewController as an item of the tab bar (buy linking them through relationship segue)
The last tableviewcontroller does appear with a navbar on top but i can't add any bar button item on it. even the code self.navigationItem.rightBarButtonItem = self.editButtonItem does not make it appear.
The thing is with the first tableviewcontroller it does work (code and designer works). I suspect it had to do something with the first nav controller.
I did try embedded in the nav controller in the tableviewcontroller but that just shoes 2 navbar.
Any help is appreciated
Thanks,
EDIT: Add storyboard screenshot
Based on my own experience, you typically use this sequence:
tabBarController -> navController -> tableViewController
In other words, a tab bar controller with a tab bar item containing a navigation controller, which in turn holds a table. If this isn't the solution you're looking for or the button doesn't show up, could you include a snapshot of your storyboard?
UPDATED:
If you are attempting to make your tab bar dynamic, you need to change the array that tabBarController.viewControllers is using. As mentioned in the comments, this isn't the best approach if you are following the interface guidelines but here's how I got it to work:
//Initial tab bar items
self.tabBarController.viewControllers =
[NSMutableArray arrayWithObjects:originalItem1, originalItem2, nil];
//Now let's replace the old items with some new ones!
self.tabBarController.viewControllers =
[NSMutableArray arrayWithObjects: replacementItem1, replacementItem2, replacementItem3, nil];
As you can see, we initially set the tab bar to contain two tab bar items (originalItem1 & 2). Then the next bit of code replaces those items with some new ones (replacementItem1 & 2 & 3). Since it appears you are trying to change the tab based on the view the app is currently in, you would probably want to include this in the viewWillLoad method. This means that the tab bar should update as the view is about to be loaded. Of course, you would need to set some conditions in nearly every view so that the tab bar would constantly be changing to the one you want.
Unfortunately, this is more of a programmatic approach and you are using storyboard. I don't see an obvious way of getting this done in the storyboard alone, but the code should be able to help.

can i add more than 8 tabs on TabBarController?

Can I add more than 8 tabs on UITabBarController?
My code is here:
UITabbarController *tabbar=[[UITabbarController alloc]init];
tabbar addTabItems......
You can add as many view controllers to UITabBarController as you want. The right most tab button will be called More with three dots which will take you to the screen where you can edit which view controllers to show and which ones to hide.
Yes you can add 8 tabbars but only 5 will be visible and for remaining, it'll show you a dotted tab on clicking that tab it'll show the list of remaining tabs in your tabbar.

How to show and hide tab bar at required places?

Hi i am making an application where ther are four screens(view controllers) from 1 to 4. I want to show screen 1 without tab bar .This screen will have three buttons through which user can navigate to other screens. Now when user taps screen 2 button then user should navigate to screen 2 with tab bar on bottom.Now this tab bar will have four tabs from screen 1 to 4 to navigate .Similarly when now user tap on tab 1 then the scrren 1 should arrive which is without tab bar and so on.
My problem is i am not able to load or unload tab bar at required places.I have tried following:
I opened screen 1 on statrt up and on screen 1's view did load added the tab bar but it didnt work
I added tab bar on main window but then tab bar starts to show even on screen 1.
PLease tell me the correct way to do this (In other words a tab bar with four tabs in which the first screen should not show tab bar)
Thanks in advance
use this single line
self.hidesBottomBarWhenPushed=YES;
for hide tab bar. use this before push the page where you want tab Bar hidden and also write this line
self.hidesBottomBarWhenPushed=No;
at same page from where you are going to push in viewWillDisappear.
self.window.rootViewController = self.navigationController;
First add your rootviewcontroller in the window.
and add three buttons in it.
on clicking event of button add tabbarcontroller to mainwindow
AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
delegate.tCtr.selectedIndex = btntag; //ur button tag;
delegate.tCtr.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:delegate.tCtr animated:YES];