0

我有以下功能,它显示我的应用程序的顶部栏。它由一个图像和一个 UIBarButton 组成。我从 viewWillAppear 中调用它。当我按下当前控制器并移至下一个控制器然后移回主控制器时,右侧的条形按钮消失。请帮忙。

-(void)setTopBar
{
    self.navigationController.navigationBar.tintColor =  [UIColor colorWithRed:0.6367 green:0.6367 blue:0.6367 alpha:1.0];
    UIImage *titleImage = [UIImage imageNamed: MAIN_TOPBAR];
    if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        //iOS 5 new UINavigationBar custom background
        [self.navigationController.navigationBar setBackgroundImage:titleImage forBarMetrics: UIBarMetricsDefault];
   //     NSLog(@"loading nav items");
        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"More Apps" style:UIBarButtonItemStylePlain target:self action:@selector(loadFAADAds)];
        rightButton.tag = 11111;
        self.navigationItem.rightBarButtonItem = rightButton;
        [rightButton release];

    } 
    else
    {
        CGRect titleFrame = self.navigationController.navigationBar.frame;
        UIImageView *titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, titleFrame.size.width,titleFrame.size.height)];
        [titleImageView setImage:titleImage];
        [titleImageView setTag:TOPBAR_TAG];

       // [self.navigationController.navigationBar sendSubviewToBack:titleImageView];
       // self.navigationItem.titleView = titleImageView;
        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"More Apps" style:UIBarButtonItemStylePlain target:self action:@selector(loadFAADAds)];

        self.navigationItem.rightBarButtonItem = rightButton;

        //self.navigationController.navigationItem.rightBarButtonItem = rightButton;
        [self.navigationController.navigationBar insertSubview:titleImageView atIndex:0];
        [self.navigationController.navigationBar sendSubviewToBack:self.navigationController.navigationBar];
        [rightButton release];
    }
    [titleImage release];

}
4

1 回答 1

-1
-(void)setTopBar
{
    self.navigationController.navigationBar.tintColor =  [UIColor colorWithRed:0.6367 green:0.6367 blue:0.6367 alpha:1.0];
    UIImage *titleImage = [UIImage imageNamed: MAIN_TOPBAR];
    if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) {
        //iOS 5 new UINavigationBar custom background
        [self.navigationController.navigationBar setBackgroundImage:titleImage forBarMetrics: UIBarMetricsDefault];
   //     NSLog(@"loading nav items");
        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"More Apps" style:UIBarButtonItemStylePlain target:self action:@selector(loadFAADAds)];
        rightButton.tag = 11111;
        self.navigationItem.rightBarButtonItem = rightButton;
       // [rightButton release];

    } 
    else
    {
        CGRect titleFrame = self.navigationController.navigationBar.frame;
        UIImageView *titleImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, titleFrame.size.width,titleFrame.size.height)];
        [titleImageView setImage:titleImage];
        [titleImageView setTag:TOPBAR_TAG];

       // [self.navigationController.navigationBar sendSubviewToBack:titleImageView];
       // self.navigationItem.titleView = titleImageView;
        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:@"More Apps" style:UIBarButtonItemStylePlain target:self action:@selector(loadFAADAds)];

        self.navigationItem.rightBarButtonItem = rightButton;

        //self.navigationController.navigationItem.rightBarButtonItem = rightButton;
        [self.navigationController.navigationBar insertSubview:titleImageView atIndex:0];
        [self.navigationController.navigationBar sendSubviewToBack:self.navigationController.navigationBar];
        //[rightButton release];
    }
//    [titleImage release];

}
于 2012-06-04T10:09:05.327 回答