Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 644
HernandoZ Avatar asked Nov 29 '22 08:11

HernandoZ


1 Answers

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];
like image 119
HernandoZ Avatar answered Dec 08 '22 13:12

HernandoZ