第二个视图中的Tabbar [英] Tabbar in Second View

查看:88
本文介绍了第二个视图中的Tabbar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个激活页面,每个用户都必须激活该应用。
一旦应用程序被激活,用户就会移动到标签栏视图。

I have an activation page in my app, which is mandatory for every user to activate the app. Once the app is activated, the user moves to the tabbed bar view.

我创建了一个标签栏应用程序,从我的activationView点击按钮我想调用标签栏,我得到一个完整的黑屏。

I have created a tabbed bar application, where from my activationView on click of button I am trying to call the tab bar, I am getting an entire black screen.

- (IBAction)moveToActivateView:(id)sender {
    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    UITabBarController *tabBarController = [[UITabBarController alloc]init];
    [self.view addSubview:tabBarController.view];
    appDelegate.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

    self.tabBarController.viewControllers = @[viewController1, viewController2];
    appDelegate.window.rootViewController = self.tabBarController;
    [appDelegate.window makeKeyAndVisible];}


推荐答案

嘿,在appDelegate中创建tabBarController的属性并在那里分配所有ViewController,然后从你的ViewController调用你的tabBarController

Hey make your tabBarController's property in appDelegate and assign all ViewController there then call your tabBarController from yourViewController

在AppDelegate.h中

@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (retain, nonatomic) IBOutlet UITabBarController *tabBarController;

在AppDelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    [self makeTabBar];

    [self addInitialVIew];

    [self.window makeKeyAndVisible];

    return YES;
}  


-(void)makeTabBar
{    
    tabBarController = [[UITabBarController alloc] init];
    tabBarController.delegate=self;
    FirstViewController *firstVC =[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];    

    UINavigationController *firstNC = [[UINavigationController alloc] initWithRootViewController:firstVC];
    firstNC.tabBarItem.title=@"Profile";
    firstVC.tabBarController.tabBar.tag = 0;


    SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

    UINavigationController *SecondNavController = [[UINavigationController alloc] initWithRootViewController:secondVC];    
    SecondNavController.tabBarItem.title = @"Search";
    secondVC.tabBarController.tabBar.tag = 1;


    NSArray *viewControllers =[[NSArray alloc]initWithObjects:firstNC,SecondNavController, nil];
    [tabBarController setViewControllers:viewControllers animated:NO];   
}

-(void) addInitialVIew
{    
    InitialViewController *initialViewController = [[InitialViewController alloc]initWithNibName:@"InitialViewController" bundle:nil];
    navigationController = [[UINavigationController alloc]initWithRootViewController:ViewController];
    [self.window addSubview:navigationController.view];
}

现在在 InitialViewController 您可以添加yourTabBar并删除 InitialViewController

Now in InitialViewController you can add yourTabBar and remove InitialViewController

- (IBAction)switchToTabBarBtnPress:(id)sender
{
    AppDelegate *appdelegte =(AppDelegate*)[[UIApplication sharedApplication]delegate];

    [[[appdelegte navigationController] view]removeFromSuperview];

    [[appdelegte window]addSubview:[[appdelegte tabBarController]view]];

    [[appdelegte tabBarController]setSelectedIndex:0];
}

并按照我的回答

回答

这篇关于第二个视图中的Tabbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆