Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ramy1989

macrumors newbie
Original poster
Nov 7, 2012
21
0
Let's say that I have a navigation controller and I push a view controller.By doing this, a button that leads me back to the previous controller is created.

I've found the navigation item holding the button this way:

Code:
UINavigationItem* backItem=self.navigationController.navigationBar.topItem;

If I change it's title also the button title changes.

But the only button is backItem.rightBarButtonItem, even if the button is displayed at the left, the other two buttons (back and right) are nil.

If I try changing the button item this way:

Code:
backItem.rightBarButtonItem.style= UIBarButtonItemStylePlain;

The title of the button leading me back doesn't change, is that another button? How do I change the style of the button leading me back to the other view controller?
 
Try something like this:

Code:
UIBarButtonItem *previous = [[UIBarButtonItem alloc] 
                             initWithTitle:@"Search"
                             style:UIBarButtonItemStyleBordered
                             target:self
                             action:@selector(SearchAction:)];
 
Is there a Reason setting.
yourViewController.navigationItem.backButtonItem = someButton;
wouldn't work for you?

If you do that to your viewControllers when you set them up, when you push the viewController on to the navigation controller the buttons will be those set for the visible viewController. You don't have to worry about reseting each time that view will appear.
 
I usually set a custom left or back button in viewDidLoad of the view controller that's been pushed.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.