how to use multiple tab bar controller in an application? - objective-c

I have several buttons in root view and I want to switch different tab bar controller when click each button. How can I do this?
I did for just first 'Denetim Formu' button. When click it it show second picture. But How can I do like this for other 'Lokasyon, Taahhüdname, Form Sorgulama, ect' buttons. Each have to show different tab bar controller.

What you can do is on your particular button click:-
1.)Which tab bar button item and its view controller you want to change(identify it).
*YourViewController* *import=[[[*YourViewController* alloc]initWithNibName:#"*YourViewControllerNibName*" bundle:nil] autorelease];
UINavigationController *baseNav = [[[UINavigationController alloc] initWithRootViewController:import]autorelease];
NSArray *arr=[[appDelegate tabBarController]viewControllers];
NSMutableArray *array=[NSMutableArray arrayWithArray:arr];
[array replaceObjectAtIndex:1 withObject:baseNav];
[[appDelegate tabBarController]setViewControllers:array];
appDelegate.tabBarController.selectedIndex=1;
UITabBarItem *item= [[[[appDelegate tabBarController]tabBar]items ]objectAtIndex:1];
item.image=[UIImage imageNamed:#"hometab.png"];
item.title=#"Home";
By this way you can change your tab bar view controller tab with its item name and image.

Related

Hiding (not removing) A UITabBarController UITabBarItem

I need to hide a button on the tab bar, but still have it accessible by code as needed. I know I can completely remove the button, but then I cannot access that view anymore.
So in my case, I want my home screen to be visible when the app first loads, but do not want the tab to show up for it. If they navigate away from that screen, I will add a custom "home" button in the navigation bar at the top.
However, if I remove the tab bar item, I no longer go to the home screen anymore but to what was originally the 2nd tab. Is there a way to only hide the tab bar item and still access it in code?
So you can see how I'm accessing the tab bar to begin with, here is how I can remove the tab bar item.
UITabBarController *tabVC = (UITabBarController *)self.window.rootViewController;
NSMutableArray *tabBarViewControllers = [NSMutableArray arrayWithArray:[tabVC viewControllers]];
[tabBarViewControllers removeObjectAtIndex:0];
[tabVC setViewControllers:tabBarViewControllers];
//or to just disable it
NSArray *tbItems = tabVC.tabBar.items;
UITabBarItem *item_0 = [tbItems objectAtIndex:0];
[item_0 setEnabled:NO];
There is an option of hiding the bottom TabBar in the attributes inspector
"Hide bottom bar on push"
You might find this link useful
How to hide/show tab bar of a view with a navigation bar in iOS?

How to get the Xcode TabView default black bar in bottom?

In a new tabbed app application when two more views are added, views which are created by default has a black bar on bottom and the two views that are manually created doesn't have that black bar ?
How to enable that black bar ?
You need to connect your two other scenes to the tab bar controller. Hold the control key down, and drag from Tab Bar View Controller to the other View Controller. When it asks what type of a segue you want to create, choose "view controllers" under the "Relationship" segue section.
If you are using NIBs, drag a view controller object from the object library into the tab bar controller. Once it's there, select the new view controller in the view controller explorer and configure the Custom Class in the Identity Inspector.
... and the name of the nib in the Attributes Inspector.
In your app delegate you should see code like this:
UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:#"FirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = #[viewController1, viewController2];
Modify it to include your third and fourth view controllers. Otherwise, how would your tab controller know your new view controllers exist!

How to put a tableView's Edit button in the toolbar when a search bar is shown (as in Apple's mail app)?

I would like to put the Edit button in the toolbar at the bottom. The Edit button is usually instantiated with self.navigationItem.rightBarButtonItem = self.editButtonItem in viewDidLoad and normally placed in the navigation bar.
When trying to put the Edit button (= self.editButtonItem) in the toolbar (by adding it to the toolbar items), the buttom does not appear. However, all other toolbar items, which I have added using Interface Builder are presented correctly.
How would you recommend adding this button to the toolbar?
The reason for adding the Edit button to the toolbar is to be enable the table's edit mode when a UISearchBar enabled search is currently active and the searchbar hides the edit button in the navigation bar.
I would like to get the same behavior as in Apple's email app, where the Edit button is shown in the toolbar when search is active.
I would appreciate any suggestions.
Thank you for your help!!
You can add a Edit button to the toolbar this way:
self.editButton =
[[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit
target:nil
action:nil]
autorelease];
NSArray *toolbarItems =
[NSArray arrayWithObjects:self.editButton,nil];
self.toolbar.items = toolbarItems;
If you want to hide/show it, just toggle its hidden property:
self.editButton.hidden = YES;
You could do it manually, by creating a new UIBarButtonItem with style UIBarButtonSystemItemEdit. Then simply add it to the tabbar, assign a target and action and call [tableView setEditing:YES animated:YES];.

How to create a tab bar on iOS?

I need on my main view controller to have a tab bar with tabs to navigate to all my other controllers. I just need the tab bar on this controller and when i get to another controller i just need to have a back button to go to the main controller.
Now i have some questions. I created the tab bar in the main view controller and all the tabs with the text and images that i need. However i see that i can only create IBOutlet for the tab bar and not IBActions for every tab(as i thought). So i created an IBOutlet and connected it to my tab bar.
How can i refer to every tab?
If i can refer to every tab how is it possible to change the view controller when a tab is selected when i cant use an action about it?(I am not asking for the code to change controllers , i am asking for the place that i should put the code so that my application knows that this specific tab was pressed and has to change controller).
Thank you for reading my post :D
You can create a UITabBarController programmatically in applicationDidFinishLaunching and set it as the root view controller (or if you prefer, you can present it as a modal view). Here is the minimal code to do it:
UITabBarController *tabBarController = [[UITabBar alloc] init];
UIViewController *controller1 = [[YourViewController alloc] init];
UIViewController *controller2 = [[YourOtherViewController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:
controller1,
controller2,
nil];
// set as the root window
window.rootViewController = tabBarController;
If you want to customize the look of the tab bar items, do so by adding overloading (UITabBarItem *)tabBarItem in the child view controller(s):
- (UITabBarItem *)tabBarItem
{
return [[UITabBarItem alloc] initWithTitle:#"Amazing" image:[UIImage imageNamed:#"Blah.png"] tag:0];
}
How to make a tab bar controller
by me
Drag tab bar controller into storyboard (hopefully you have one)
Control-drag from tab bar controller to each view you want hooked up to it
Pop bottles
Just so you know, this gives you the default tab bar controller behavior (so it will always be present and you can click from any page to another). If that's not what you want, then don't use a tab bar controller. To do otherwise is an abomination.
Storyboards are definitely helpful, but if you don't want to use one that's fine. Doing the Control Drag from the Tab Bar Controller to your new View Controller does indeed work (Dustin's response).

UINavigationController - Start with middle view

In my application, I've 7 views and they are based on navigation.
When the app starts, I want to show the 3rd view in navigation.
So that user can navigate to 4th view as usual or user can navigate to 2nd view by clicking "Back" button on the top left.
How can I make my navigation controller show 3rd view directly?
Use viewControllers property and popToViewController method:
navigationController.viewControllers = [NSArray arrayWithObjects:firstViewController, secondViewController, thirdViewController, ...., nil];
[navigationController popToViewController:thirdViewController animated:NO];