2

I'm new to iOS development. I'd like to know, how to add a back button to a VC, I don't have a navigation bar also. The method of 'embedding' it will also not work, as I have to change a few things. Is there an easier method? Thanks in advance.

shravan.sukumar
  • 109
  • 2
  • 11
  • Just to make it clear: you can't add a back button and a navigation bar to a storyboard. Storyboard is just a file containing view controllers and views. You can add it to a view controller that's in the storyboard. Can you show us what you currently have - screen shot the part of your storyboard showing your view controller where you want to have a back button and a navigation bar. – Andrej Jul 03 '16 at 19:44
  • https://dl.dropboxusercontent.com/u/62578523/test.tiff I want to add a back button to the 'detailed event view controller' – shravan.sukumar Jul 03 '16 at 19:46

1 Answers1

3

Since you said that you don't want to embed it in navigation controller, you can drag&drop UINavigation Bar from the sidebar:

enter image description here

Andrej
  • 7,266
  • 4
  • 38
  • 57
  • Should I connect this to my ViewController? – shravan.sukumar Jul 03 '16 at 20:00
  • Just drag and drop it inside. Then you'll have to also drag and drop the button inside the navigation bar. You should connect the button to you view controller swift file using something like this: `@IBAction func backButtonPressed(sender: AnyObject) {}`. – Andrej Jul 03 '16 at 20:11
  • You can look here at matt's answer for help for setting custom height: http://stackoverflow.com/questions/32142375/changing-the-height-of-the-navigation-bar-ios-swift – Andrej Jul 03 '16 at 20:14
  • I did as you said, dragged and dropped a 'bar button item' connected it to my VC, and wrote this inside the button method, 'let backItem = UIBarButtonItem(title: "Custom", style: .Plain, target: nil, action: nil) navigationItem.backBarButtonItem = backItem' It still doesn't work. What Am I doing wrong? – shravan.sukumar Jul 03 '16 at 20:29
  • Inside the button method you should write what ever you want to happen when the button is tapped: Some ideas: `print("Tapped")` or `dismissViewControllerAnimated(true, completion: nil)`. – Andrej Jul 03 '16 at 20:39
  • Thank you so much! Got what I needed! – shravan.sukumar Jul 03 '16 at 20:44