1

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

self.navigationItem.rightBarButtonItem = self.editButtonItem;

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

回答

0
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"YOUR TITLE" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease]; 
+0

正是我所做的,但它不工作!没有出现 – PiccoloBuddha 2010-09-23 09:16:59

+0

你如何推视图控制器?你能给我你使用的确切线吗?它会类似于:[self.navigationController pushViewController:nextPage animated:YES];' – 2010-09-23 09:28:15

+0

它是:[self.navigationController pushViewController:tab animated:YES];哪里的标签有一个TabBarController里面有3个其他视图,如果我把一个按钮放在标签类上,它变得可见在每个视图内的tabController – PiccoloBuddha 2010-09-23 09:41:53

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]; 
+0

什么也没有出现,也许每个视图都使用了导航栏,并且不可能仅为其中一个按钮添加按钮。我不知道它是否会改变某些内容,但我的第一个视图中包含一个tabBar,其中还包含其他三个视图 – PiccoloBuddha 2010-09-23 09:19:24

2

还有一点要添加到答案中指出别人的是,添加工具栏上的按钮,请确保您访问其添加到UINavigationController.You应该是你的视图控制器像这样修改视图控制器..

navController=[[UINavigationController alloc] initWithRootViewController:viewController]; 
[viewController.navigationItem setRightBarButtonItem:rightBarButton];