我想在导航控制器推送和弹出的所有 UIViewControllers 的底部工具栏中添加一个 UILabel:
- (void)init
{
//Bottom toolbar label
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0 , 11.0f, 320, 21.0f)];
[self.titleLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14]];
[self.titleLabel setBackgroundColor:[UIColor clearColor]];
[self.titleLabel setTextColor:[UIColor whiteColor]];
[self.titleLabel setText:@"Selected Comics: 0"];
[self.titleLabel setTextAlignment:UITextAlignmentLeft];
}
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
UIBarButtonItem *labelButton = [[UIBarButtonItem alloc] initWithCustomView:self.titleLabel];
UIBarButtonItem *flex = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil] autorelease];
[viewController setToolbarItems:[NSArray arrayWithObjects:labelButton, flex, sortButton, nil] animated:animated];
[labelButton release];
}
但是,在我推送并弹出视图控制器后,标签出现并立即消失。另一个按钮 (sortButton) 仍然可见。
我应该怎么做才能保持标签可见?
谢谢