无法推回导航控制器中嵌入的视图控制器

Cannot push back to view controller embed in Navigation Controller

我创建了 ViewController A (a.k.a vcA) 和 vcB 嵌入​​到导航视图控制器中,将故事板中的子视图控制器映射为 classes.m

当我尝试构造视图控制器 A->B->A 的重定向,或从 vcB 创建 vcA 时,使用:

A : 
    PairViewController * sliderVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PairViewController"];
    sliderVC.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentViewController:sliderVC animated:NO completion:nil];
    sliderVC.view.backgroundColor =  [UIColor clearColor];


B :     ViewController *destinationController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
     [destinationController setBle:_ble];
            [destinationController setLeDevice:selectedDevice];

            destinationController.modalPresentationStyle = UIModalPresentationCurrentContext;

     [self presentViewController:destinationController animated:NO completion: nil] ;

新建A,没有出现任何导航栏。

当我使用

[self.navigationController pushViewController:destinationController animated:nil]; 

xCode表示异常;

Cannot call pushNavigationItem:animated: directly on a UINavigationBar managed by a controller.'

能否请您告诉我如何从 vcB 创建 vcA,并且我的自定义导航栏保持完整,不丢失?

在 A 中,我尝试使用此方法构建导航栏,但如果从 vcB 创建 vcA,导航栏将变成 nil

-(void)viewWillLayoutSubviews{

    navigationBar=  [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 44)];

}

- (void)viewWillAppear:(BOOL)animated {


    [self.navigationController setNavigationBarHidden:NO];

    navigationBar =  self.navigationController.navigationBar;
    [navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                            [UIColor whiteColor], NSForegroundColorAttributeName,
                                            [UIFont fontWithName:@"TitilliumText22L-Medium" size:22.0], NSFontAttributeName,
                                            nil] ];

    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"FPV Control"];

    UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
    [button setImage:[UIImage imageNamed:@"menu_back.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];

    //    UIBarButtonItem *buttonItemA = [[UIBarButtonItem alloc] initWithCustomView:button];

    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                                                       target:self action:@selector(buttonClicked:)];

    [leftBarButtonItem setCustomView:button];
    navigationItem.leftBarButtonItem = leftBarButtonItem;

    UIButton *buttonA = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 70, 20)];
    [buttonA setImage:[UIImage imageNamed:@"rc_logo.png"] forState:UIControlStateNormal];
    UIBarButtonItem *buttonItemB = [[UIBarButtonItem alloc] initWithCustomView:buttonA];
    navigationItem.rightBarButtonItem = buttonItemB;
    [navigationBar pushNavigationItem:navigationItem animated:NO];


    NSLog(@" navigaytion item  :  %@" ,  navigationItem);
    NSLog(@" navigaytion bar  :  %@" ,  navigationBar);

因此请按如下方式展示您的 ViewController 和 NavigationController。

MyViewController *myViewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
UINavigationController *navigationController = 
    [[UINavigationController alloc] initWithRootViewController:myViewController];

//now present this navigation controller modally 
[self presentViewController:navigationController
                   animated:NO
                   completion:nil];