2015-06-10 61 views
0

我有一个问题给你: 我有一套UIViewController附加到self.tabBarController.viewControllers 和我有另一个单独应该是登录scree只出现一次(你第一次打开应用程序),我希望加载,以防万一用户没有登录,否则或之后,用户登录,它会加载我有完整的self.tabBarController.viewControllers。 下面是代码:viewControllers不会出现

-(void)load_login_view{ 
    NSLog(@"map"); 
    UIViewController * fb_login = [[FacebookLoginView alloc]init]; 
    fb_login.title = @"fsf ss"; 
    UINavigationController * fb_login_navigation = [[UINavigationController alloc] initWithRootViewController:fb_login]; 
    [fb_login_navigation.tabBarItem setImage:[UIImage imageNamed:@"eventi.png"]]; 
} 



- (void)applicationDidBecomeActive:(UIApplication *)application { 
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    BOOL login_status = [defaults objectForKey:@"login_status"]; 


    UIViewController * secondpage = [[SecondViewController alloc]init]; 
    secondpage.title = @"second"; 
    UINavigationController * secondpage_navigation = [[UINavigationController alloc] initWithRootViewController:secondpage]; 
    [secondpage_navigation.tabBarItem setImage:[UIImage imageNamed:@"eventi.png"]]; 



    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    self.tabBarController = [[UITabBarController alloc] init]; 
    self.tabBarController.viewControllers = @[secondpage_navigation]; 
    self.window.rootViewController = self.tabBarController; 


    if(!login_status){ 
     [self load_login_view]; 
    }else{ 

    } 

    [self.window makeKeyAndVisible]; 

} 

回答

1

你有很多方法可以做到这一点。有几个例子。

  1. 根据您当前的导航流程

- >如果用户没有登录,则可以显示你的登录视图控制器模式,因此会在你tabBarController的顶部。 //类似的东西

-(void)load_login_view{ 
    UIViewController * fb_login = [[FacebookLoginView alloc]init]; 
       fb_login.title = @"fsf ss"; 

    UINavigationController * fb_login_navigation = [[UINavigationController alloc] initWithRootViewController:fb_login]; 

    [self.window.rootViewController presentViewController:fb_login_navigation animated:NO completion:nil]; 

    } 

- >当用户登录,解雇登录控制器。如果需要,下次保存用户数据

- >如果需要,请更新TabBarcontroller中选定的控制器。

  • 更改导航流
  • - >使用UINavigationController与登录控制器([[UINavigationController alloc] initWithRootViewController:fb_login]),为rootController为应用程序

    UIViewController * fb_login = [[FacebookLoginView alloc]init]; 
    fb_login.title = @"fsf ss"; 
    UINavigationController * fb_login_navigation = [[UINavigationController alloc] initWithRootViewController:fb_login]; 
    self.window.rootViewController = fb_login_navigation; 
    

    - 当>你的用户被记录下来,推送到你的TabBar控制器。如果需要的话,保存用户数据,下一次

    //inside fb_login controller (you can optimize the code, it's just a quick example) 
    
    UIViewController * secondpage = [[SecondViewController alloc]init]; 
    secondpage.title = @"second"; 
    UINavigationController * secondpage_navigation = [[UINavigationController alloc] initWithRootViewController:secondpage]; 
    [secondpage_navigation.tabBarItem setImage:[UIImage imageNamed:@"eventi.png"]]; 
    self.tabBarController = [[UITabBarController alloc] init]; 
    self.tabBarController.viewControllers = @[secondpage_navigation]; 
    [self.navigationController pushViewController:tabBarController animated:YES]; 
    

    为 - >以避免双重征税的导航栏(fb_login_navigation/secondpage_navigation),你可以隐藏的fb_login_navigation导航需要的时候。

    - >下一次,如果用户登录,您可以在加载登录控制器后启动上面的代码,而不是等待用户输入他的凭据。

    希望它有帮助。