0

I have a UICollectionViewController which acts like a paging, each cell has its own page. On navigation bar, it always shows "Back". The following wouldn't change the title.

-(void)viewWillAppear:(BOOL)animated{
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
                               initWithTitle: @"Back Button Text"
                               style: UIBarButtonItemStyleBordered
                               target: nil action: nil];

[self.navigationItem setBackBarButtonItem: backButton];
Agustin Meriles
  • 4,866
  • 3
  • 29
  • 44
user1688346
  • 1,846
  • 5
  • 26
  • 48
  • are you running this code in the parent view controller or in the child? – tkanzakic Apr 25 '13 at 21:09
  • I don't understand your question. – user1688346 Apr 25 '13 at 21:11
  • when you call `setBackBarButtonItem` you are modifying the back button shown by the controllers you push from this controller, if you want to modify the back button shown by the controller you have to modify the `leftBarButtonItem` property – tkanzakic Apr 25 '13 at 21:14

1 Answers1

3

You'll need to use this code:

self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Custom Title"
        style:UIBarButtonItemStyleBordered
       target:nil
       action:nil];

Note that you need to set this on the view controller that the back button will point to. For example, if ViewControllerA pushed ViewControllerB onto the nav stack, then you would use this code on ViewControllerA.

Undo
  • 25,519
  • 37
  • 106
  • 129