0
votes

Displaying an UIViewController modally from one of the View Controllers(which are in a Navigation controller) code :

self.present(viewController, animated: true, completion: nil)

Within the modal ViewController, a custom Navigation Bar along with navigation item is added. In which, i'm trying to display the Back Button.

let backButton = UIBarButtonItem()
backButton.title = "Back"
self.navigItem.backBarButtonItem = backButton  //self.navigItem is the custom Navigation Item

Is there something im missing here?

thanks in advance, Rajesh

2
present VC does not embed with Navigationcontroller, if you need embed your VC in nav controller and present your VC, else progrmatically create navigation bar in presented VC - Anbu.Karthik
VC needs to be presented modally not added in the nav controller, Have added the custom Navigation Bar in the StoryBoard for this viewcontroller. Im able to add/show other bar button items except back button. - Rajesh Rs
Im able to add the left button item as Back, can i access the system back icon to set or i need to add as part of the image assets and access? - Rajesh Rs
add as part of the image assets and access? -- is better - Anbu.Karthik

2 Answers

0
votes
 let btnleft : UIButton = UIButton(frame: CGRect(x:0, y:0, width:35, 
                           height:35))
 btnleft.contentMode = .center
 btnleft.setImage(Set_Local_Image("arrow_left"), for: .normal)
 btnleft.addTarget(self, action: #selector(YOUR_ACTION), for: .touchDown)

 let backBarButon: UIBarButtonItem = UIBarButtonItem(customView: btnleft)
 self.navigationItem.setLeftBarButtonItems([menuBarButon], animated:false)
0
votes

In Swift3 try this code on the viewDidLoad

    self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "arrow_left")
    self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "arrow_left")
    UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), for:UIBarMetrics.default)
    self.navigationController?.navigationBar.tintColor = UIColor.white
    self.navigationItem.hidesBackButton = false