0

In a UIViewController viewDidLoad method I customize icon and behavior of the navigation left button this way:

let backButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target:self, action:#selector(handleBack))
self.navigationItem.leftBarButtonItem = backButton

Is there any way to restore its original appearence and behavior?

enter image description here

  • what do you mean? – zombie Nov 15 '16 at 12:00
  • 1
    No you can't do that, you have only option to have a custom back image which looks similar to the original, and toggle as you need. – iphonic Nov 15 '16 at 12:08
  • you mean the ones in the old iOS versions? – DeyaEldeen Nov 15 '16 at 12:21
  • @zombie: as you know, you can change the left button in the navigation bar. I simply asked if, once "overriden" the original button (with its "go back" functionality) it is possible to restore its behavior –  Nov 15 '16 at 12:52
  • 1
    @iphonic: so, if you want to restore the original behavior, all you have to do is redefine its icon and behavior –  Nov 15 '16 at 12:53
  • @DeyaEldeen: in my current version of iOS (the latest) there are back buttons with arrow, etc. –  Nov 15 '16 at 12:53

3 Answers3

1
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.hidesBackButton = NO
0

You will have to do it this way:

In viewDidLoad method, add this:

self.navigationItem.hidesBackButton = YES;
let backButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.action, target:self, action:#selector(handleBack))
self.navigationItem.leftBarButtonItem = backButton;

To revert back, do this:

self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = NO;
atulkhatri
  • 10,896
  • 3
  • 53
  • 89
  • This is the same thing I wanted to do but I thought there was some other way, that's why I asked –  Nov 15 '16 at 13:03
0

the navigation bar only supports these

buttons

I gone through extracting iOS assets assets with this and it was so annoying to calibrate the back button to not look fake even though i used the extracted, my advice is let the navigation controller handle this for you by keeping the back that appears when pushing to stack.

DeyaEldeen
  • 10,847
  • 10
  • 42
  • 75
  • Problem is not always is the case. That is: sometimes, in some viewcontroller, you don't need the back functionality. For example, when a user is logged in, you want to put in that position an icon showing his avatar (when you click that avatar you access a section where the user can edit his profile), etc. –  Nov 15 '16 at 13:58