2015-06-09 185 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"];