Ios 在viewController上添加默认导航栏

Ios 在viewController上添加默认导航栏,ios,objective-c,Ios,Objective C,我有一个按钮,按下它会显示一个新的viewController,就像一个弹出窗口 - (IBAction)btnPressed:(id)sender { PopUpObj = [[PopUpViewController alloc] init]; [self.navigationController presentViewController:PopUpObj animated:YES completion:nil]; } 视图按其应显示,但没有带“后退”按钮的导航栏 在Po

我有一个按钮,按下它会显示一个新的viewController,就像一个弹出窗口

- (IBAction)btnPressed:(id)sender
{
    PopUpObj = [[PopUpViewController alloc] init];

    [self.navigationController presentViewController:PopUpObj animated:YES completion:nil];
}
视图按其应显示,但没有带“后退”按钮的导航栏

在PopUpViewController中,我创建了如下导航栏:

- (void)viewDidLoad
{
self.view.backgroundColor = [UIColor whiteColor];

UINavigationBar *navbar = [[UINavigationBar alloc]initWithFrame:CGRectMake(0, 0, 320, 64)];
[navbar setBarStyle:UIBarStyleDefault];
[self.view addSubview:navbar];

UIBarButtonItem* myBackButton = [[UIBarButtonItem alloc]
                                 initWithTitle:@"Back"
                                 style:UIBarButtonItemStyleBordered
                                 target:nil
                                 action:nil];

self.navigationItem.backBarButtonItem = myBackButton;

[super viewDidLoad];
}

导航栏出现,但“后退”按钮项根本不出现。怎么了?

当您将另一个viewController推到导航堆栈上时,将显示
BackbarButtonim
。可以将其视为返回PopUpViewController的按钮,而不是显示PopUpViewController时显示的按钮。将
self.navigationItem.BackBarButtonim
更改为
self.navigationItem.LeftBarButtonim

是否尝试使用pushViewController而不是presentViewController加载弹出式视图控制器?是的,它会工作,但我希望viewcontroller从底部向上滑动,而不是从左侧滑动。我可以改变pushViewController的segue样式吗?所以问题是您的PopUpViewController不知道它在NavController中。您可以尝试将其包装在NavController中并演示它。