Changing the style of a bar button item

Discussion in 'iOS Programming' started by ramy1989, Dec 27, 2012.

  1. macrumors newbie

    Joined:
    Nov 7, 2012
    #1
    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?
     
  2. macrumors newbie

    polarsirkelen

    Joined:
    Jan 2, 2013
    Location:
    Tromsø, Norway
    #2
    Try something like this:

    Code:
    UIBarButtonItem *previous = [[UIBarButtonItem alloc] 
                                 initWithTitle:@"Search"
                                 style:UIBarButtonItemStyleBordered
                                 target:self
                                 action:@selector(SearchAction:)];
     
  3. macrumors 68030

    MattInOz

    Joined:
    Jan 19, 2006
    Location:
    Sydney
    #3
    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.
     
  4. macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #4
    You must change the button before you push on the new view controller.
     
  5. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    I usually set a custom left or back button in viewDidLoad of the view controller that's been pushed.
     

Share This Page