![](/img/trans.png)
[英]create a UILabel when view appears and destroy it when view disappears
[英]UILabel appears and disappears from the bottom bar of UIViewControllers
我想将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)仍然可见。
如何使标签可见?
谢谢
您的问题是:self.titleLabel。
多个labelButton实例都引用该视图,并且当您设置工具栏项目时(我假设动画== YES),titleLabel将从您不希望看到的其超级视图中删除。
为每种用法创建一个新的titleLabel,您的问题将消失。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.