简体   繁体   中英

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

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.

On iPhone, modal views occupy the entire screen, so there is no room for a nav bar. Thus you do not need a navigation controller.

I assume the above code is inside a UIViewController instance. 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:

  [self dismissModalViewControllerAnimated:YES/NO];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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