Joshua Joshua - 10 months ago 57
iOS Question

Replace back button but keeping swipe to navigate back

First of all, I have noticed that there is a similar question. However, I would like to ask about the solution in Swift. Here is my code:

override func viewDidLoad() {
navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Button", style: .Plain, target: self, action: nil)

I want to replace the back button but keeping the swipe for user to navigate back. However, this disables the swipe. I cannot get the accepted answer and the suggested answer in the link above to work. Here is what I tried to translated into Swift.

let appearanceNavigationBar = UINavigationBar.appearance()
appearanceNavigationBar.backIndicatorImage = UIImage(named: "back")
appearanceNavigationBar.backIndicatorTransitionMaskImage = UIImage(named: "back")
appearanceNavigationBar.tintColor = UIColor.whiteColor()

I am using Xcode 8.0 beta, Swift 2.3 and testing in iOS 10.0. Any help would be greatly appreciated.


I used this and it worked:

self.navigationController.interactivePopGestureRecognizer.delegate = nil;