ios - 未出现的 View Controller

标签 ios objective-c uiviewcontroller

我有一个问题要问你: 我有一组 UIViewController 附加到 self.tabBarController.viewControllers 我有另一个单独的应该是只出现一次的登录屏幕(第一次打开应用程序),我希望加载那个以防用户未登录,否则或之后用户登录,它将加载我拥有的完整 self.tabBarController.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. 根据您当前的导航流程

-> 如果用户未登录,您可以将登录 View Controller 显示为模式,以便它将位于 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];

    }

->当您的用户登录时,关闭登录 Controller 。如果需要,保存用户数据以备下次使用

->如果需要的话,做一些工作来更新 TabBarcontroller 中选定的 Controller 。

  1. 改变你的导航流程

-> 将 UINavigationController 与登录 Controller ([[UINavigationController alloc] initWithRootViewController:fb_login]) 一起用作应用程序的根 Controller

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 Controller 。如果需要,保存用户数据以备下次使用

//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的导航。

-> 下一次,如果用户已登录,您可以在加载登录 Controller 后立即触发上面的代码,而不是等待用户输入他的凭据。

希望对您有所帮助。

关于ios - 未出现的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30766208/

相关文章:

ios - 仅在用户关闭警报后显示下一个屏幕

ios - Cocos2d v3 在子节点上应用着色器

ios - 在设备中查看网络应用程序时如何推荐 native 应用程序?

iphone - 在计算角度时避免使用 atan2 - atan2 精度

iphone - IOS文件关联-打开特定文件的默认应用程序

UIView 和 AutoresizingMask 被忽略

Swift,对于一些 UIViews 在点击时到他们的整体 Controller

ios - 确定加载当前 UIViewController 的 UIViewController

iphone - 多次更自然地为点设置动画

ios - 两次初始化 NSString 对象是否有任何隐藏的副作用