在UITabBarController之前显示XIB? [英] Display XIB before UITabBarController?

查看:118
本文介绍了在UITabBarController之前显示XIB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm facing this problem for a couple of months and i don't know what is the best solution to solve it.The problem is,i need to load a XIB before my UITabBar shows up,more clearly,i have my first view which is to the user login(NO TABBAR SHOULD BE DISPLAYED),when user login,the app verify the information and after should load the view with a UITabBarController,but every time i try do that without presenting the login view modally,both of the views are displayed,the login view and the tabbar view.

推荐答案

您可以先将loginViewController设置为 rootViewController 的主 window ,然后在用户登录后,将tabBarController设置为 rootViewController

You could set first the loginViewController as rootViewController of your main window, then after the user is logged in, set the tabBarController as rootViewController.

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

Something like this (assume your loginViewController is 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;
}

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

Then from the loginViewController call the method setTabBar of the appDelegate.

LoginViewController.m
#import "AppDelegate.h"

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

这篇关于在UITabBarController之前显示XIB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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