2014-03-29 42 views
0

我有一个应用程序,它有一个登录导航控制器和一个标签栏控制器。我已经将我的标签栏控制器设置为根控制器,但是我希望登录导航控制器显示为模式,以便在登录时可以将其解除,而如果是的话,则可以不显示它。它正在阅读正确的内容,但未能提供landingviewcontroller。当我运行应用程序时,它直接跳转到TabBarController。作为模态iOS呈现登录?

我的代码如下:

我有检查,如果你是在我的应用程序委托这是我要告诉它呈现着陆视图控制器(登录)登录的方法。我从步进通过其正确判断,我不是在登录和去这行代码上运行的知道:

[self.window.rootViewController presentViewController:landingVC animated:YES completion:nil]; 

完整的应用程序的委托:

#import "GFAppDelegate.h" 
#import "GFCredentialStore.h" 

@implementation GFAppDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:[NSBundle mainBundle]]; 
    UIViewController *tabBarController = [storyboard instantiateInitialViewController]; 
    UIViewController *landingVC = [storyboard instantiateViewControllerWithIdentifier:@"LandingViewController"]; 

    GFCredentialStore *store = [[GFCredentialStore alloc] init]; 

    if (store.isLoggedIn) { 
     self.window.rootViewController = tabBarController; 
    } else { 
     [self.window.rootViewController presentViewController:landingVC animated:YES completion:nil]; 
    } 


    // Set root view controller and make windows visible 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

我试着要清楚这一点,但要理解这可能是因为写得不好而令人困惑。谢谢你的帮助。

回答

1

试试这个:

self.window.rootViewController = tabBarController; 
[self.window makeKeyAndVisible]; 
if (store.isLoggedIn==false) { 
    [tabBarController presentViewController:landingVC animated:YES completion:nil]; 
} 
+0

非常感谢。完美的作品。任何想法我可以在loginViewController中解雇这个,我必须导入“AppDelegate”或创建一个ViewController的新实例,以在单独的控制器中访问它。 – jckly

+0

[self dismissViewControllerAnimated:YES completion:nil]; - 在loginViewController – xexe

+0

再次感谢!整理出来。 – jckly

2

你需要做的是始终将rootViewController设置为tabBarController,但是如果用户没有登录,就从它调用presentViewController。类似的东西:

self.window.rootViewController = tabBarController; 
[self.window makeKeyAndVisible]; 
if (!store.isLoggedIn) { 
    [tabBarController presentViewController:landingVC animated:YES completion:nil]; 
} 
+0

也完美的作品。接受第一个回答。这是完美的,并且更加简洁!你有什么想法可以实现我在回复主要答案的评论中所提问的内容吗?谢谢你的帮助。 – jckly

+1

其实我的回答是第一个,如果你看看时间戳:) – sha

1

你的问题是,当试图从self.window.rootViewController呈现视图控制器是不存在,因此rootViewController == nil

我建议你不要将它作为模式呈现(因为你没有控制器来呈现),而是以root身份设置登录视图控制器。

self.window.rootViewController = landingVC; 

但是,如果您的意图是提供上方标签栏上的登录,请参阅我之前建议的答案。

+0

谢谢,我之前有过这样的设置,但我希望显示标签作为根,因为这样做会导致登录后导航控制器问题。 Upvoted。 – jckly