ios - appdelegate 如何使用 Storyboard推送 ViewController

标签 ios ios6 storyboard

在我的应用程序委托(delegate)中,如果保存了用户详细信息,我会将用户推送到 View Controller

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  // cached user
    PFUser *currentUser = [PFUser currentUser];
    if (currentUser)
    {
        NSLog(@"current user signing and looking for VC %@", currentUser);
        // A user was cached, so skip straight to the main view

        UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
        TaskSelectionViewController*viewController = [[TaskSelectionViewController alloc] initWithUser:currentUser];
        [navigationController pushViewController:viewController animated:YES];

                NSLog(@"VC found");
            } else {
                NSLog(@"VC not found");
    }

TaskSelectionViewController.m

 -(id)initWithUser:(PFUser *)currentUser
{
NSLog(@"current user %@", currentUser);

NSLog(@"task Selection initwithuser");
return self;
 }

推送有效,但我得到的只是顶部的 NavigationController 栏和黑屏。

缺少什么??

感谢您的帮助。

最佳答案

好的,使用 instantiateViewControllerWithIdentifier:@"ID"完成

UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
TaskSelectionViewController *controller = (TaskSelectionViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"task"];
[navigationController pushViewController:controller animated:YES];

关于ios - appdelegate 如何使用 Storyboard推送 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14153453/

相关文章:

swift - 为游戏的主菜单制作 Storyboard?

ios - 是否可以通过远程通知的方式打开iOS应用?

ios - Xamarin Forms Maps Circle 自定义渲染器

ios - 试图给 UILabel 一个阴影,但它不会出现

ios - sqlite数据库只更新1条记录

storyboard - Storyboard在 iOS 5 中如何工作?

ios - 无法从选项卡栏 Controller 访问导航栏

ios - UITableViewCell 为不同的方向和单元格类型加载自定义 XIB

ios - iPad编程,有什么方法可以编程反转颜色?

ios - UIDocument closeWithCompletionHandler : completes immediately