从ViewController推送到UITabBar

时间:2014-03-04 20:05:26

标签: ios iphone objective-c

我在下面创建了appDelegate方法。这为3个viewcontrollers FixtureViewController,WorldCupViewController和MenuViewController创建了一个tabBar。我的RootController设置为loginViewController,它将确保您在进入下一个ViewController之前登录。当一个人登录时我想将它推送到tabBarController?我怎么能这样做。

我已尝试在loginViewController中推送到第一个菜单,即MenuViewController,但这不会显示UITabBar。

tabBarController = [[UITabBarController alloc] init];

MenuViewController *firstTab = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstTab];


FixtureViewController *secondTab = [[FixtureViewController alloc] initWithNibName:@"FixtureViewController" bundle:nil];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondTab];

WorldCupViewController *thirdTab = [[WorldCupViewController alloc] initWithNibName:@"WorldCupViewController" bundle:nil];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:thirdTab];

LoginViewController *loginView = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:loginView];



self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[navController, navController2, navController3];


[self.window setRootViewController:navController4];
[self.window makeKeyAndVisible];

2 个答案:

答案 0 :(得分:0)

我相信你会推送整个tabBarController,而不仅仅是第一个标签。所以在你的LoginViewController中:

#import "YourAppDelegate.h"

...

-(void)someMethod {
    YourAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    UITabBarController *tabBarController = appDelegate.tabBarController;
    [self.navigationController pushViewController:tabBarController animated:YES];
}

请注意,这假设您在AppDelegate的接口(.h)文件中有一个公开可见的UITabBarController属性。

答案 1 :(得分:0)

你试试这个:

NSArray* newArray = [NSArray arrayWithArray: youTabBar.viewControllers];
 [youTabBar setViewControllers:newArray animated:YES];
 [youTabBar setSelectedIndex:0];
 [self.window setRootViewController: youTabBar];