jeudi 27 mars 2014

how to add TabBarItems to UITabBar


Vote count:

0




I have a UITabBar on a UIViewController, I have set the UITabBar delegate and this is how I set the UITabBar up inside my viewDidLoad method



// Load UITabBar for FindModels View & call tabBar delegates
findModelsTabBar = [[UITabBar alloc] init];
findModelsTabBar.delegate = self; // This sets up tabbardelegate method

[findModelsTabBar setTranslucent:NO];
findModelsTabBar.backgroundColor = [UIColor lightGrayColor];
findModelsTabBar.frame = CGRectMake(0.0, screenRectTabBar.size.height - 110, screenRectTabBar.size.width, 45.0);
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:colorController.lgRed/255.0 green:colorController.lgGreen/255.0 blue:colorController.lgBlue/255.0 alpha:1.0]];

[self.view insertSubview:findModelsTabBar aboveSubview:self.tableView]; // add tabBar to the mainView (appears at the bottom of the screen)


Then I have my delegate method like so



#pragma TabBar delegate
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
switch (item.tag) {
case 0:
{
NSLog(@"0");
}
break;
case 1:
{
NSLog(@"1");
}
break;
case 2:
{
NSLog(@"2");
FindModelsViewController *findModelsViewController = [[FindModelsViewController alloc] initWithNibName:@"FindModelsViewController" bundle:nil];

// Sets the back button for the new view that loads (this overrides the usual parentview name with "Back")
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:nil action:nil];

[self.navigationController pushViewController:findModelsViewController animated:YES];

// Set Delegates so you can get the data back
[findModelsViewController setDelegate:self];
}
break;
default:
break;
}
}


I would like to know how to create a UITabBar Item with an Image and when clicked would call that tabBar delegate...


any help would be appreciated.



asked 44 secs ago






Aucun commentaire:

Enregistrer un commentaire