我是ios的新手,我的tabbar控制器出了问题。我正在我的项目中使用两个标签栏控制器。一个是在应用程序午餐时加载它运行良好。我想在didselect行加载另一个。如何做到这一点。我做了很多实验,但没有任何效果。
答案 0 :(得分:0)
-(void) hidetabbar {
[UIView animateWithDuration:0.5
animations:^{
for(UIView *view in tabBarController.view.subviews)
{
if([view isKindOfClass:[UITabBar class]])
{
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
}
} else {
if (hiddenTabBar) {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
} else {
[view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
}
}
}
}];
hiddenTabBar = !hiddenTabBar;
}
when u r clicking on the table view did select row hide the tabbar in the viewcontroller that u r sending
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
[((AppDelegate*)[[UIApplication sharedApplication]delegate]) hidetabbar];
}
-(void)tabBarControllerView
{
tabBarController = [[UITabBarController alloc] init];
tabBarController.view.backgroundColor = [UIColor blackColor];
tabBarController.delegate = self;
//Add some tabs to the controller...
//----First tab----//
//-----second Tab -----//
//------3rd tab--//
//-----4th tab bar--------//
//-----5th tab bar--------//
[self.view addSubview:tabBarController.view];
[navigationController pushViewController:tabBarController animated:YES];
tabBarController.tabBar.tag=100;
tabBarController.view.hidden = NO;
}
- (void)tabBarController:(UITabBarController *)tabBarControllers didSelectViewController:(UIViewController *)viewController
{
if (tabBarControllers.selectedIndex == 0)
{
}
else if (tabBarControllers.selectedIndex == 1)
{
}
else if (tabBarControllers.selectedIndex == 2)
{
}
else if (tabBarControllers.selectedIndex == 3)
{
}
else if (tabBarControllers.selectedIndex == 4)
{
}
}
隐藏该视图控制器中的主标签栏,您可以在其中执行did选择表并添加另一个标签栏。 试试这样的事情可能会对你有所帮助
答案 1 :(得分:0)
在didSelect事件中添加以下代码
UITabBarController *tabBarController = [[UITabBarController alloc]init];
NSArray*tabBarimageArray=[NSArray arrayWithObjects:@"firstTabImage.png",@"secondTabImage.png", nil];
YourFirstTabRootViewController *firstVc = [[YourFirstTabRootViewController alloc]initWithNibName:@"YourFirstTabRootViewController" bundle:nil];
UINavigationController *firstNavigationController=[[UINavigationController alloc]initWithRootViewController:firstVc];
YourSecondTabRootViewController *secondVc = [[YourSecondTabRootViewController alloc]initWithNibName:@"YourFirstTabRootViewController" bundle:nil];
UINavigationController *secondNavigationController=[[UINavigationController alloc]initWithRootViewController:secondVc];
NSArray *VCs = [[NSArray alloc] initWithObjects:firstNavigationController,secondNavigationController nil];
NSArray *names = [NSArray arrayWithObjects:
NSLocalizedString(@"Tab1", @""),
NSLocalizedString(@"Tab2", @""),
nil];
NSMutableArray *tabBarViewControllers = [[NSMutableArray alloc] initWithCapacity:[VCs count]];
NSInteger index = 0;
for (id controller in VCs) {
UINavigationController * navController = controller ;
// THIS SETS UP THE TAB BAR ITEMS/IMAGES AND SET THE TAG FOR TABBAR_ITEM_TAGS
NSString *tabName = [names objectAtIndex:index];
UIImage *tabImage = [UIImage imageNamed:[NSString stringWithFormat:[tabBarimageArray objectAtIndex:index]]];
navController.title = tabName;
UITabBarItem *tempTab = [[UITabBarItem alloc] initWithTitle:tabName
image:tabImage
tag:index];
navController.tabBarItem = tempTab;
[tabBarViewControllers addObject:navController];
index ++;
}
[ tabBarController setViewControllers:tabBarViewControllers];
[self presentModalViewController:tabBarController animated:YES];