1

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

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

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

这是一个 mesAlertbuttonpressed 的例子

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

在此处输入图像描述

4

3 回答 3

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];
于 2013-08-06T12:17:28.917 回答
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];


    }     
于 2013-08-06T12:33:15.477 回答
0

如果我理解你的话,我不确定。您的视图是否已被视图控制器控制?如果没有,那么您的操作将不起作用。

你可以尝试显示它模式:

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

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

于 2013-08-06T12:24:58.753 回答