0

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

8
  • 1
    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 Commented Aug 31, 2017 at 11:24
  • 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. Commented Aug 31, 2017 at 11:27
  • see this example stackoverflow.com/questions/21448766/… Commented Aug 31, 2017 at 11:33
  • 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? Commented Aug 31, 2017 at 11:38
  • add as part of the image assets and access? -- is better Commented Aug 31, 2017 at 11:40

2 Answers 2

0
 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)
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.