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

时间:2011-06-03 15:11:59

标签: iphone uinavigationcontroller modalviewcontroller

请帮我解决这个问题 这真的很不稳定我无法在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;

请帮助我,我已经尝试了几乎所有的排列组合。

Thnx提前

1 个答案:

答案 0 :(得分:1)

看起来好像要在模态视图中显示mapView。

在iPhone上,模态视图占据整个屏幕,因此没有导航栏的空间。因此,您不需要导航控制器。

我假设上面的代码在UIViewController实例中。如果是这样,请执行以下操作:

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

在这种情况下,在你的mapView控制器中,你应该添加一个按钮,按下时按钮执行此操作:

  [self dismissModalViewControllerAnimated:YES/NO];