2010-09-07 99 views
2
-(void)viewWillAppear:(BOOL)animated { 
//setup toolbar 
[self.navigationController setToolbarHidden:NO]; 
self.navigationController.toolbar.barStyle = UIBarStyleBlackTranslucent; 
self.navigationController.toolbar.alpha = .8; 
self.navigationController.toolbar.tintColor = [UIColor colorWithRed:6.0/255.0 green:95.0/255.0 blue:163.0/255.0 alpha:1]; 

//setup items 
UIBarButtonItem *item1 = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self.navigationController.toolbar action:nil]; 
UIImage *imageUp = [UIImage imageNamed:@"up.png"]; 
UIBarButtonItem *item2 = [[UIBarButtonItem alloc] initWithImage:imageUp style:UIBarButtonItemStylePlain target:self action:@selector(toggleUp:)]; 
item2.width = 5; 
UIImage *imageDown = [UIImage imageNamed:@"down.png"]; 
UIBarButtonItem *item3 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil]; 
UIBarButtonItem *item4 = [[UIBarButtonItem alloc] initWithImage:imageDown style:UIBarButtonItemStylePlain target:self action:@selector(toggleDown:)]; 
UIBarButtonItem *item5 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil]; 
UIBarButtonItem *item6 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(toggleDown:)]; 
UIBarButtonItem *item7 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; 


NSArray *itemsArray = [[NSArray alloc] initWithObjects:item1, item2, item3, item4, item5, item6, item7, nil ]; 


[self setToolbarItems:itemsArray]; 


...more 

} 

我不知道这里发生了什么,我已经读了很多关于如何为工具栏做,但我似乎无法得到任何的UIBarButtonItems的显示。UINavigationController的工具栏:问题设置UIBarButtonItems

任何想法?

回答

4

对不起,上面搞砸了代码。

我找到了我的问题的答案。 我正在访问的UINavigationController的孩子,而不是根UIView。 我将上面的代码分配给viewWillAppear到我的UINavigationController的根UIViewController,它工作。因此,要显示它只是在我的子的UIViewController我必须设置

[self.navigationController setToolbarHidden:NO]; 

所有的人我不希望工具栏上可见UIViewControllers。

希望这可以帮助别人。谢谢