我在导航工具栏中遇到问题。我在我的应用程序委托中设置了导航工具栏背景图像,然后有一个按钮,单击它时会更改导航工具栏背景图像并移动到另一个视图。弹出视图时未恢复自定义导航栏背景
但是,当我点击后退按钮并返回到原始视图时,导航工具栏背景图像不会改回。
下面是相关代码:
在我的第一个视图控制器:
- (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