开发者

UINavigationController Toolbar : problem setting UIBarButtonItems

 -(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] initWithObject开发者_运维问答s:item1, item2, item3, item4, item5, item6, item7, nil ];


 [self setToolbarItems:itemsArray];


...more

} 

I am not sure what is happening here and I have read a lot about what to do for the toolbar but I cannot seem to get any of the UIBarButtonItems to display.

Any ideas?


Sorry for the messed up code above.

I have found the answer to my question. I was accessing a child of the UINavigationController and not the root UIView. I assigned the code above to the viewWillAppear to the root UIViewController of my UINavigationController and it worked. So to show it only on my sub UIViewController I had to set

[self.navigationController setToolbarHidden:NO];

To all the UIViewControllers that I do not want the toolBar to be visible on.

Hope this helps someone out. Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜