标签栏控制器的实现

时间:2013-08-06 12:13:10

标签: iphone ios uitabbarcontroller uitabbar

此视图显示5个按钮(抱歉是法语)

this view present 5 buttons(sorry is in french)

我想在选择一个按钮时实现tabbarcontroller,它将导航到tabbarControllerClass我的问题,我不知道如何在每个按钮中编程动作以推送到此视图

  

这是mesAlertbuttonpressed

的一个例子
-(IBAction)MesAlertsButtonPressed:(id)sender{
TabBarControllerViewController *tabBarControllerViewController = [[TabBarControllerViewController alloc]initWithNibName:@"TabBarControllerViewController" bundle:nil];
tabBarControllerViewController.TypeView=@"Alert";
[self.navigationController pushViewController:tabBarControllerViewController animated:YES];

enter image description here

3 个答案:

答案 0 :(得分:1)

AppDelegate.m类中创建方法,并在想要显示tabController时调用该方法例如:

-(void)setRootViewControllerTab1{

    UIViewController *viewController1, *viewController2, *viewController3, *viewController4, *viewController5;
    UINavigationController *navviewController1 , *navviewController2, *navviewController3, *navviewController4, *navviewController5;

    viewController1 = [[[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil] autorelease];
    navviewController1=[[UINavigationController alloc]initWithRootViewController:viewController1];

    viewController2 = [[[HowItWorksViewController alloc] initWithNibName:@"HowItWorksViewController" bundle:nil] autorelease];
    navviewController2=[[UINavigationController alloc]initWithRootViewController:viewController2];

    viewController3 = [[[JoiniAppointViewController alloc] initWithNibName:@"JoiniAppointViewController" bundle:nil] autorelease];
    navviewController3=[[UINavigationController alloc]initWithRootViewController:viewController3];


    viewController4 = [[[BecomeBussUserViewController alloc] initWithNibName:@"BecomeBussUserViewController" bundle:nil] autorelease];
    navviewController4=[[UINavigationController alloc]initWithRootViewController:viewController4];

    viewController5 = [[[ContactUsViewController alloc] initWithNibName:@"ContactUsViewController" bundle:nil] autorelease];
    navviewController5=[[UINavigationController alloc]initWithRootViewController:viewController5];

    self.tabBarController.viewControllers = [NSArray arrayWithObjects:navviewController1, navviewController2,navviewController3,navviewController4,navviewController5, nil];

    self.window.rootViewController = self.tabBarController;

    [self.window makeKeyAndVisible];
}

并在该按钮点击事件上调用该方法,如下所述..

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegate setRootViewControllerTab1];

答案 1 :(得分:1)

使用此行代码调用方法来创建标签栏 -

AppDelegate *appDelegateObj = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDelegateObj createTabBar];

实际方法

  -(void)createTabBar
    {
        self.tabBarController.customizableViewControllers = nil;   

            Home *homeObj =  [[Home alloc] initWithNibName:@"Home" bundle:nil];
            UINavigationController *tab1Controller = [[UINavigationController alloc] initWithRootViewController:homeObj];     

            ChatList *chatListObj = [[ChatList alloc] initWithNibName:@"ChatList" bundle:nil];
            UINavigationController *tab2Controller = [[UINavigationController alloc] initWithRootViewController:chatListObj];


            Settings *settingObj = [[Settings alloc] initWithNibName:@"Settings" bundle:nil];
            UINavigationController *tab3Controller = [[UINavigationController alloc] initWithRootViewController:settingObj];  

            self.tabBarController.viewControllers = [NSArray arrayWithObjects: tab1Controller, tab2Controller,tab3Controller, nil];
            self.tabBarController.selectedIndex=0;
            self.tabBarController.delegate = self;


            self.window.backgroundColor=[UIColor clearColor];
            self.tabBarController.view.backgroundColor=[UIColor clearColor];


            self.window.rootViewController = self.tabBarController;

            [self.window makeKeyAndVisible];


    }     

答案 2 :(得分:0)

如果我理解你的话,我并不害羞。 您是否已查看视图控制器已注册?如果没有,那么你的行动将无效。

您可以尝试将其显示为模态:

-(IBAction)MesAlertsButtonPressed:(id)sender
{
    TabBarControllerViewController *tabBarControllerViewController = [[TabBarControllerViewController alloc]initWithNibName:@"TabBarControllerViewController" bundle:nil];
    tabBarControllerViewController.TypeView=@"Alert";
    [self presentModalViewController:tabBarControllerViewController animated:YES];
}

否则你应该阅读有关UINavigationController的文档。