In viewDidLoad I have a UINavigationBar with a custom background implemented in the following way:
[self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:nav_bg_image]] atIndex:100];
On the top of the stack (call it RVC) I have the following complete code:
UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:navbar_image_logo]];
[self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:nav_bg_image]] atIndex:100];
[self.navigationItem setTitleView:logoView];
[logoView release];
This works brilliantly. However, when I push a new VC on the stack and use the same code in viewDidLoad
UIImageView *logoView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:navbar_image_logo]];
[self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:nav_bg_image]] atIndex:1];
[self.navigationItem setTitleView:logoView];
[logoView release];
UIBarButtonItem *hButton = [[UIBarButtonItem alloc] initWithTitle:@"Filters" style:UIBarButtonItemStylePlain target:self action:@selector(filtersAction)];
self.navigationItem.rightBarButtonItem = hButton;
[hButton release];
Neither the “Filters” button nor the titleView imageView appears. However, I know the filters button has been added to the UI because if I click in the area that it is supposed to appear, the action is performed.
Furthermore, when I drill down to a detail view DVC and go back, all of the sudden the titleView (logoView) appears!
I suspect that this is some sort of memory issue but I have not been able to resolve it.
There is a mention of the issue you are having with ordering at iDev Recipes How do iPhone apps Instagram/Reeder/DailyBooth implement custom NavigationBars with variable width back buttons?
Basically you are adding your background in the wrong way.
Support only iOS 5
Implement a method like
setBackgroundImage:forBarMetrics:Support Older iOS’s + iOS 5
Subclass
UINavigationBarand implement thedrawRectTo get a
UINavigationControllerto use your subclass you need to create it using a xib.If you have set everything up in code then you will still need to use a nib to do this.
The nib I use has no
File's Ownerand only contains aNavigation Controllerthat is configured to use myCustomNavigationBarand has noviewControllersIn this case I set this up in code like this:
Then present this controller however I normally would. The controller/window that presents it will take the required retain on the
UINavigationController