How to override self.navigationItem.backBarButtonItem Action?
STILL, No direct access for changing target and action on self.navigationItem.backBarButtonItem
.
I ended up using the first one i tried... and get my (custom) image..
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"myImage.png"]
style:UIBarButtonItemStyleBordered
target:self
action:@selector(backButtonOverrideAction:)];
[self.navigationItem setLeftBarButtonItem:backButton];
while...
//this two lines of code are still useless, i just feel sorry for them..
[self.navigationItem.backBarButtonItem setTarget:<#(id)#>];
[self.navigationItem.backBarButtonItem setAction:<#(SEL)#>];
You cannot assign action to back BarButton. The solution for that is to create the custom back button.
In swift 3.1
override func viewDidLoad() {
// set navigationItem.leftBarButtonItem return to Root
let backToRootVCButton = UIBarButtonItem.init(title: "Back", style: UIBarButtonItemStyle.plain, target: self, action: #selector(backToRootVCAction))
self.navigationItem.setLeftBarButton(backToRootVCButton, animated: true)
}
func backToRootVCAction() {
_ = self.navigationController?.popToRootViewController(animated: true)
}