1

我正在尝试开发我的第一个 iphone 应用程序。我正在使用具有三个视图的导航控制器:主视图->第一视图->第二视图。我想只在第一个视图上添加一个按钮,我试过这样:

self.navigationItem.rightBarButtonItem = self.editButtonItem;

但什么也没有出现。如果我在主视图上添加按钮,它出现在每个视图之后,可以做我想做的事吗?谢谢!

4

3 回答 3

2

要添加到其他人指出的答案的另一点是,要在工具栏上添加一个按钮,请确保您正在访问添加到 UINavigationController 的视图控制器。您应该像这样修改视图控制器。

navController=[[UINavigationController alloc] initWithRootViewController:viewController];
[viewController.navigationItem  setRightBarButtonItem:rightBarButton];
于 2011-12-24T19:11:43.310 回答
0
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"YOUR TITLE" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
于 2010-09-23T08:52:01.500 回答
0
UIButton *button =  [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:[UIImage imageNamed:@"buttonImage.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[button setFrame:CGRectMake(0, 0, 49, 30)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
于 2010-09-23T08:57:19.820 回答