简体   繁体   English

iphone:无法在导航栏上显示返回按钮

[英]iphone : unable to show back button on navigation bar

please help me with this this is really erratic I am unable to add a button to navigation bar of modalview请帮帮我这真的很不稳定我无法在modalview的导航栏中添加按钮

UINavigationController *tempModalVC=[[UINavigationController alloc] init];
[tempModalVC.navigationBar setBarStyle:UIBarStyleBlack];
//UIBarButtonItem *tempDoneBTN=[[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:self action:@selector(hideModalView:)];

UIBarButtonItem *tempDoneBTN=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(hideModalView:)];

[tempModalVC.navigationItem setBackBarButtonItem:tempDoneBTN];
[tempModalVC.navigationItem setTitle:@"Title"];
tempModalVC.navigationItem.backBarButtonItem.enabled=YES ;
//[tempModalVC.navigationBar setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(hideModalView:)]];
//[tempModalVC.navigationItem setRightBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(hideModalView:)]];
[tempDoneBTN release];
[tempModalVC.view addSubview:mapView];

tempModalVC.modalPresentationStyle = UIModalPresentationFormSheet;

Please help me with this I have tried almost every permutation combination.请帮我解决这个问题,我已经尝试了几乎所有的排列组合。

Thnx in advance提前谢谢

It looks as if you want to display a mapView in a modal view.看起来好像您想在模态视图中显示 mapView。

On iPhone, modal views occupy the entire screen, so there is no room for a nav bar.在 iPhone 上,模态视图占据了整个屏幕,因此没有导航栏的空间。 Thus you do not need a navigation controller.因此,您不需要导航 controller。

I assume the above code is inside a UIViewController instance.我假设上面的代码在 UIViewController 实例中。 If so, just do this:如果是这样,只需执行以下操作:

  [self presentModalViewController:mapView animated:YES/NO];

In this case, in your your mapView controller, you should add a button that, when pressed does this:在这种情况下,在您的 mapView controller 中,您应该添加一个按钮,当按下该按钮时:

  [self dismissModalViewControllerAnimated:YES/NO];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM