2012-05-24 151 views
1

我用下面的代碼來導航欄上顯示的UIImage導航欄返回按鈕消失

-(void)hideTopBanner:(bool)b; 
{ 
    if(b) 
    { 

     [UIView animateWithDuration:0.35 animations:^{ 

     UIView *bannerView =[self.navigationController.navigationBar viewWithTag:999]; 
      [bannerView setFrame:CGRectMake(-320, 8, 144, 30)]; 


     }]; 
    } 
    else { 

     [UIView animateWithDuration:0.35 animations:^{ 



      UIView *bannerView =[self.navigationController.navigationBar viewWithTag:999]; 
      [bannerView setFrame:CGRectMake(88 , 8, 144, 30)]; 



     }]; 
    } 
} 

// --------------

UIImageView *bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"topbg1.png"]] ; 
[bgImageView setFrame:CGRectMake(0, 0, 320, 46)]; 
[self.navigationController.navigationBar addSubview:bgImageView]; 
bgImageView.tag=999; 
[bgImageView release]; 

我嘗試使用

UIBarButtonItem *myBarButtonItem = [[UIBarButtonItem alloc] init]; 
    myBarButtonItem.title = @back"; // or whatever text you want 
    self.navigationItem.backBarButtonItem = myBarButtonItem; 
    [myBarButtonItem release]; 

顯示後退按鈕,但沒有顯示

但是當它導航到另一個視圖控制器。 導航欄上的後退按鈕消失。

歡迎任何評論

+0

你有沒有嘗試設置任何所有權的ViewController? –

回答

0

確保你的新視圖控制器(你導航到一個)有一個標題。當我的觀點沒有設置標題時,我遇到了這個問題。

0

如果一切失敗(設置標題等),使用此:

UIBarButtonItem *myBarButtonItem = [[UIBarButtonItem alloc] init]; 
[myBarButtonItem addTarget:self action:@selector(myBarButtonItemPressed) forControlEvents:UIControlEventTouchUpInside]; 
myBarButtonItem.title = @"back"; // or whatever text you want 
self.navigationItem.leftBarButtonItem = myBarButtonItem; 
[myBarButtonItem release]; 

- (void)myBarButtonItemPressed 
{ 
    // Do your stuff, like pop view controller 
}