2015-12-25 86 views
-4

我是iOS編程的新手,對編程方式調用ViewControllers知之甚少。我正在製作一個應用筆記,我想讓它受到密碼保護。我使用TabBarController,其中一個選項卡用於設置(用於啓用和禁用密碼保護)。當應用程序啓動時,我想知道,密碼保護啓用或禁用。如果啓用,我想顯示一個登錄屏幕(即調用不同的視圖控制器)。我認爲我應該從AppDelegate中的didFinishLaunchingWithOptions方法做到這一點,但我不知道如何去做。我嘗試了一些方法,但失敗了。請幫助我。如何使用TabBarController從AppDelegate調用視圖控制器(即didFinishLaunchingWithOptions)

在此先感謝。

+2

你能顯示你試過的代碼嗎? –

回答

-1

抱歉關於倒票 - 我不認爲你應得的。我在啓動iOS時遇到了同樣的問題。這可能有幫助

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

    //set NSDefaults when you set if password protection is needed - here you are checking to see if password enabling exists 

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
    BOOL passwordExists; 
    passwordExists = [defaults boolForKey:@"hasCompleted"]; 

    //jump to different view controller depending if BOOL is false or true 
    //set names (ShowLogInScreenController) In StoryBoardID in the Interface Builder 
    UIStoryboard *storyBoard =[ UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    UINavigationController *vc = [storyBoard instantiateViewControllerWithIdentifier:passwordExists ? @"ShowLogInScreenController" : @"PasswordProtectionDisabledViewController"]; 
    UINavigationController *questionsNavigationController = [[UINavigationController alloc] initWithRootViewController:vc]; 
    questionsNavigationController.navigationBar.hidden = YES; 
    self.window.rootViewController = questionsNavigationController; 
    return YES; 
} 
+0

非常感謝漢娜 –

+0

它工作正常,但問題是,現在我的標籤欄不可見。 –

相關問題