我的导航工具栏有问题。我在我的app委托中设置了导航工具栏背景图像,然后有一个按钮,当点击时,它会改变导航工具栏背景图像并移动到另一个视图。
这个工作得很好,但是,当我点击后退按钮并返回到原始视图时,导航工具栏背景图像不会变回来。
相关代码如下:
在第一个视图控制器中:
- (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];
}
导航栏只有一张图片。如果你更改了它,之后你想要更改回来,你必须自己更改它。
我建议你给每个视图控制器一个navigationBarImage
属性。为导航控制器设置一个委托。在委托中,添加这个方法:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
UIImage *image = [(id)viewController navigationBarImage];
if (image)
[navigationController.navigationBar setBackgroundImage:image forBarMetrics: UIBarMetricsDefault];
}