簡體   English   中英

UILabel在UIViewControllers的底部欄中顯示和消失

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM