Reputation: 5857
I have implemented a custom title view for my navigation bar, containing an image and a label. This view is aligned to the left of the bar, by setting its origin.x to 10 pixels.
So far so good, but when I push a view controller and then go back to the main screen, the title view is centered instead of positioned on the left.
I tried setting its left and back bar button items to nil and its origin.x to 10, but nothing seems to work. I tried both viewWillAppear and viewDidAppear:
CGRect frame = self.navigationItem.titleView.frame;
frame.origin.x = 10;
self.navigationItem.titleView.frame = frame;
self.navigationItem.backBarButtonItem = nil;
self.navigationItem.leftBarButtonItem = nil;
How can I accomplish this?
Upvotes: 1
Views: 1644
Reputation: 366
First off you should set up the navigationItem in viewDidLoad (after calling [super viewDidLoad]) NOT viewWill/DidAppear.
Are you only setting up the navigationItem on the second view controller and not the main vc???
If so you need to set the navigationItem on both, or alternatively in a Base View Controller class which both view controllers should subclass.
Upvotes: 1