Search code examples
iosobjective-cuinavigationcontrollerappdelegateback-button

Objective-C: Back Button disappear after present/push ViewController from AppsDelegate


The pic below is my storyboard and I wish to present the Upcoming VC at AppDelegate. Below is my code at AppDelegate I manage to present the Upcoming VC when called.

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc=[sb instantiateViewControllerWithIdentifier:@"Upcoming"];
UINavigationController *nv = [[UINavigationController alloc] initWithRootViewController:vc];
nv.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.window.rootViewController presentViewController:nv animated:YES completion:nil];

At the Upcoming VC, I manage to present the navigationBar with title and background colour but my back button < remain missing. My back button is auto generated.

-(void)viewWillAppear:(BOOL)animated{

    self.navigationController.navigationBar.hidden = NO;

    [self.navigationItem setHidesBackButton:FALSE];
    //====Make the navigation Bar appear===
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = nil;

    //=== Set the navigation Back < color
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setBarTintColor : [ UIColor grayColor]];
    //=== Set the navigation Bar text color
    [self.navigationController.navigationBar
    setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.translucent = NO;

}

Please help.

Pic1


Solution

  • What do you expect then ?

    back button will be only visible when you push your UpcomingVC from existing ViewController remember that just taking navigation bar in storyboard will now show backbutton automatically.

    You can create full view controller hierarchy

    Like

    UpcomingVC is pushed from HomeVC then you can set HomeVC as root view controller embedded in UINavigationController and to the next line you can push UpcomingVC with animation false