4

在我的应用程序委托中,如果保存了用户详细信息,我会将用户推送到视图控制器

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");
    }

任务选择视图控制器.m

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

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

推送正在工作,但我得到的只是顶部的 NavigationController 栏和黑屏。

缺什么 ??

谢谢你的帮助。

4

2 回答 2

24

使用 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];
于 2013-01-05T05:59:27.507 回答
0

-(id)initWithUser:(PFUser *)currentUserTaskSelectionViewController 中,您应该调用[super init]或类似的方法来正确初始化 ViewController。这至少为我解决了类似的问题。

查看 Apple 的示例以获取视图控制器初始化方法的参考实现。

于 2013-01-04T16:45:02.320 回答