NavigationController完成按钮未显示

时间:2012-01-21 21:44:28

标签: iphone

当我按下主视图控制器上的信息按钮时,它会以模态方式显示navbar和uitextview,但不会显示完成按钮。

    - (void) modalViewAction:(id)sender     

 self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];

[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

 _viewController = [[ModalViewController alloc] init];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];

 navigationController.navigationBar.tintColor = [UIColor brownColor];

self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(Done:)] autorelease];

[self.navigationController presentModalViewController:self.viewController animated:YES];

[navigationController release];

任何人都知道为什么导航控制器中缺少Done Button。

感谢您的帮助。

3 个答案:

答案 0 :(得分:1)

你的模仿:

[self.navigationController presentModalViewController:self.viewController animated:YES];

您需要将其推入导航堆栈:

[self.navigationController pushViewControler:self.viewController animated:YES];

现在,NavigationController将为您处理后退按钮。

答案 1 :(得分:1)

您必须:

  1. 将视图控制器推到导航控制器上(如Hubert 解释),或
  2. 创建一个新的UINavigationController并设置 viewController作为rootViewController UINavigationController然后你可以这样做:
  3.   

    [self.navigationController   presentModalViewController:newNavigationController animated:YES];

答案 2 :(得分:0)

我添加了以下声明

[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];

到下面的代码,现在导航控制器上显示完成按钮

 - (void) modalViewAction:(id)sender

{
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease]; 

[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

 _viewController = [[ModalViewController alloc] init];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:_viewController];

UIBarButtonItem * button = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:    UIBarButtonSystemItemDone target:self action:@selector(dismissView:)] autorelease];

[_viewController.navigationItem setLeftBarButtonItem:button animated:YES];

navigationController.navigationBar.tintColor = [UIColor brownColor];

[self.navigationController presentModalViewController:self.viewController animated:YES];

[self.view addSubview:navigationController.view];

[navigationController release];

}

所以我的问题已经解决了。

感谢您的帮助