2015-06-09 246 views
0

我最近開始了一個新項目,在成功設置登錄頁後,我出現了一個問題。登錄後呈現視圖控制器

如果我在有效憑據在文本字段中鍵入,我的應用程序應該做到以下幾點:

if (user) { 
    [self.delegate loginViewControllerDidLogin:self]; 
    ... 

的「如果用戶」部分是指一切正常。經過幾個小時的搜索後,我得知我的[self.delegate loginViewControllerDidLogin:self];應該在AppDelegate.m文件中定義。在這裏,我寫了下面的代碼:

- (void)loginViewControllerDidLogin:(LoginViewController *)controller { 
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; 
    UIViewController * ViewController = [[UIViewController alloc] init]; 

    [self.window addSubview:ViewController.view]; 
    [self.window.rootViewController presentViewController:ViewController animated:YES completion:nil]; 
} 

我的問題是,我無法定義視圖控制器在我的故事板,所以我不能與視圖控制器本身的代碼連接。

所以基本上我想應用在登錄後打開一個新的視圖控制器

+0

爲什麼不能在故事板上定義ViewController? – psobko

+0

我不知道如何......在ViewController.h中試過它,但即使在我將它導入AppDelegates.m文件後,它也無法識別它。 – Annoonny

回答

0

在你的故事板中選擇要顯示並填寫「故事板ID」的視圖控制器: enter image description here

然後將其實例化爲:

UIViewController * ViewController = [storyboard instantiateViewControllerWithIdentifier:@"YourVCStoryboardID"];