简体   繁体   中英

appdelegate how to pushViewController with storyboard

In my app delegate I am pushing the user to a view controller if the user details are saved

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

The push is working but all I get is the NavigationController bar at the top and a black Screen.

what is missing ??

thanks for your help.

OK done using 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];

In the -(id)initWithUser:(PFUser *)currentUser of TaskSelectionViewController you should call [super init] or something similar to have your ViewController initialized properly. This solved a similar problem for me at least.

Look at Apple's examples for reference implementations of initialization methods of view controllers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM