整个应用程序的iPhone工具栏

我有我的应用程序基于navigationController 。 所以我设置工具栏可见的一些意见和其他人我没有调用setToolbarHidden:NOYES 。 第一个问题,这个在viewWillAppear方法中呢?

然后在我的appDelegate ,我把一个项目在工具栏上,但没有被显示。 有人可以告诉我如何使用委托协议在这里,所以每个视图知道该怎么办,当一个项目被按下?

我的代码:

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { //create itemViewcontroller EventosViewController *itemsViewController = [[EventosViewController alloc] init]; //create UINavigationcontroller, stack only contains itemviewcontroller navController=[[UINavigationController alloc] initWithRootViewController:itemsViewController]; //navController will retain itemviewcontroller, we can release it [itemsViewController release]; UIBarButtonItem *systemItem1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(pressButton1:)]; //Use this to put space in between your toolbox buttons UIBarButtonItem *flexItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; //Add buttons to the array NSArray *items = [NSArray arrayWithObjects: systemItem1, flexItem,nil]; //release buttons [systemItem1 release]; [flexItem release]; //add array of buttons to toolbar [navController.toolbar setItems:items animated:NO]; //set navController's view in window hierarchy [[self window] setRootViewController:navController]; [navController release]; // Override point for customization after application launch. [self.window makeKeyAndVisible]; return YES; } 

thx提前!

我们默认隐藏的工具栏。 toolbarItems应该存储在相应的视图控制器中,而不是导航控制器中。

从文档 :

显示一个工具栏
在iOS 3.0和更高版本中,导航控制器对象可以轻松为导航界面的每个屏幕提供自定义工具栏。 导航控制器对象现在在其视图层次结构中pipe理可选的工具栏。 显示时,此工具栏从活动视图控制器的toolbarItems属性中获取当前的一组项目。 当活动视图控制器改变时,导航控制器更新工具栏项目以匹配新视图控制器,在适当的时候将新项目animation化到适当的位置。

导航工具栏默认是隐藏的,但您可以通过调用导航控制器对象的setToolbarHidden:animated:方法来显示导航工具栏。 如果并非所有视图控制器都支持工具栏项目,则委托对象可以调用此方法在随后的推送和popup操作中切换工具栏的可见性。

你可以保持像这样的toolbaritems

 ThemeDetailViewController *themeDetail = [[ThemeDetailViewController alloc] init]; [self.navigationController pushViewController:themeDetail animated:YES]; themeDetail.toolbarItems = self.parentViewController.toolbarItems;