2014-03-29 43 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