在UITabBarController之前显示XIB?

Mat*_*eus 0 iphone xcode uitabbar ios

我正面临这个问题几个月,我不知道什么是解决它的最佳解决方案.问题是,我需要在我的UITabBar出现之前加载一个XIB,更清楚,我有我的第一个视图这是用户登录(NO TABBAR应该显示),当用户登录时,应用程序验证信息,之后应该使用UITabBarController加载视图,但每次我尝试这样做而不以模态方式呈现登录视图时,两者都是显示视图,登录视图和标签栏视图.

Mat*_*Mat 5

您可以首先设置loginViewController作为rootViewControllermain window,然后在用户登录后,将tabBarController 设置为rootViewController.

像这样的东西(假设你的loginViewController是viewController1):

Appdelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    UINavigationController *myNav1=[[UINavigationController alloc] initWithRootViewController:viewController1];
    UINavigationController *myNav2=[[UINavigationController alloc] initWithRootViewController:viewController2];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:myNav1,myNav2, nil];
    //set the login view
    self.window.rootViewController = viewController1;
    [self.window makeKeyAndVisible];
    return YES;
}

-(void)setTabBar{
    //self.viewController1=nil;
    self.window.rootViewController = self.tabBarController;
}
Run Code Online (Sandbox Code Playgroud)

然后从loginViewController调用appDelegate的方法setTabBar.

LoginViewController.m
#import "AppDelegate.h"

-(void)loginOK{
   AppDelegate *del=(AppDelegate*)[[UIApplication sharedApplication] delegate];
   [del setTabBar];
   //you could add some animation transition between views
}
Run Code Online (Sandbox Code Playgroud)