Objective-C:后退按钮在 AppDelegate present/push ViewController 后消失

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

下图是我的故事板,我想在 AppDelegate 上展示 Upcoming VC。下面是我在 AppDelegate 的代码,我设法在调用时显示 Upcoming VC

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

Upcoming VC,我设法展示了 navigationBar with title and background colour,但我的后退按钮 < 仍然不见了。我的后退按钮是自动生成的。

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

}

请帮忙。

那你期待什么?

后退按钮仅在您从现有 ViewController 按下 UpcomingVC 时可见 请记住,只需在情节提要中使用导航栏,现在就会自动显示后退按钮。

您可以创建完整的视图控制器层次结构

喜欢

UpcomingVCHomeVC 推送,然后您可以将 HomeVC 设置为嵌入在 UINavigationController 中的根视图控制器,然后推送到下一行 UpcomingVC 动画 false

你可以试试这个 故事板到故事板

ViewControllerName * next = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerName"];
[self.navigationController pushViewController:next animated:YES];

您必须已注册 nib。