In View Did Load
//--- Add Custom Left Bar Button Item ---//
self.addLeftNavItemOnView()
func addLeftNavItemOnView ()
{
// hide default navigation bar button item
self.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = true;
let buttonBack: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
buttonBack.frame = CGRectMake(0, 0, 40, 40)
buttonBack.setImage(UIImage(named:"ImageName.png"), forState: UIControlState.Normal)
buttonBack.addTarget(self, action: "leftNavButtonClick:", forControlEvents: UIControlEvents.TouchUpInside)
var leftBarButtonItem: UIBarButtonItem = UIBarButtonItem(customView: buttonBack)
self.navigationItem.setLeftBarButtonItem(leftBarButtonItem, animated: false)
}
func leftNavButtonClick(sender:UIButton!)
{
self.navigationController?.popViewControllerAnimated(true)
}
Thanks Naveen, I was trying the similar solution from 2 days but it wasn't successful, I don't know right now how but by adding following two lines from your code it worked for me.
ReplyDeleteself.navigationItem.leftBarButtonItem = nil;
self.navigationItem.hidesBackButton = true;
You just saved my bacon...been on this hoohar for 4 days now!! THANKS ;-)
ReplyDeleteDoes not compile any more, use
ReplyDeletelet buttonBack: UIButton = UIButton(type: UIButtonType.Custom) as UIButton