0

I want to add an Action to my standard Back-Button, but this won't work as I found from below link:

add-target-to-stock-back-button-in-navigationbar

So I created a custom button with an action.

UIBarButtonItem(title: "❮ Back", style: .Bordered, target: self, action: "back:")

But how can I set the standard left wing to the title?

The character '❮' is way smaller than that from the standard button. I use the standard button throughout my app, and I want to keep this optic.

Community
  • 1
  • 1
DanKas
  • 95
  • 1
  • 11

1 Answers1

0

If you want to "add" some functionality to your back button you can use the UINavigationControllerDelegate.

When you press the back button, the navigation controller will call navigationController(willShowViewController:) so you can use this to do whatever you want to do. An example is shown below:

Using UINavigationControllerDelegate:

class ViewController: UIViewController, UINavigationControllerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()

        navigationController?.delegate = self
    }

    func navigationController(navigationController: UINavigationController, willShowViewController viewController: UIViewController, animated: Bool) {
        // Add whatever you want to do here
    }
}
Eendje
  • 8,815
  • 1
  • 29
  • 31