我在導航工具欄中遇到問題。我在我的應用程序委託中設置了導航工具欄背景圖像,然後有一個按鈕,單擊它時會更改導航工具欄背景圖像並移動到另一個視圖。彈出視圖時未恢復自定義導航欄背景
但是,當我點擊後退按鈕並返回到原始視圖時,導航工具欄背景圖像不會改回。
下面是相關代碼:
在我的第一個視圖控制器:
- (void)viewDidLoad
{
[super viewDidLoad];
//set to change the navigation toolbar to this background image (the first) when this view loads
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"QuickGrocery Logo Updated.jpg"] forBarMetrics:UIBarMetricsDefault];
}
按鈕動作:
- (IBAction)wellBalancedMealsClicked:(id)sender {
QuickGroceryMasterViewController *masterViewController = [[QuickGroceryMasterViewController alloc] initWithNibName:@"QuickGroceryMasterViewController" bundle:nil];
[masterViewController setRecipeChoice:1];
//changes the navigation toolbar background image
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Keep It Balanced.jpg"] forBarMetrics:UIBarMetricsDefault];
}
你的代碼是不工作的原因是'回到你的第一個視圖控制器時viewDidLoad'不叫。只有從視圖控制器的視圖加載視圖控制器的視圖時,纔會調用此方法。 Rob Mayoff的回答是最好的解決方案。 – jrturton