我想将UILabel添加到导航控制器推送和弹出的所有UIViewControllers的底部工具栏中:
- (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)仍然可见。
如何保持标签可见?
感谢
答案 0 :(得分:0)
你的问题是:self.titleLabel。
多个labelButton实例都引用该视图,并且当您设置工具栏itmes(animated == YES我假设)时,titleLabel将从其超级视图中删除,而您不期望它。
为每种用法创建一个新的titleLabel,您的问题就会消失。