-1

enter image description hereI am making an app in xCode using Swift, and I need help with something. How do I program a UIButton that I added on a Scene on my Storyboard to navigate towards the previously used Scene (there are more than one Scenes in my app).For Example; if Im in scene3 and I'm navigated towards the scene with the UIButton, how can I program it to take me back to scene3 instead of the main menu? Or if I were in Scene2 and was navigated to the Scene with the UIButton, and I want it to take me to Scene2 instead of Scene3 or Main Menu.

Thank you

The Blue Scenes represent the levelScenes that will lead to the redScene after the level is done, however I want the UIButton to lead back to the exact same levelScene after it is pressed

CoolMAn
  • 1,851
  • 2
  • 12
  • 23
  • This depends a lot on your specific view controller layout and segues. I think if you add a photo of your storyboard you will get a better response. – Fred Faust Aug 06 '15 at 15:23
  • Thanks for the input, I put up the ScreenShot of my storyboard :) – CoolMAn Aug 06 '15 at 15:35
  • This is what you're looking for: http://stackoverflow.com/a/15839298/4096655 – Fred Faust Aug 06 '15 at 15:38
  • Although the link you provided was helpful, it isn't quite what I'm looking for. You see, Im trying to create a UIButton that will take me to the previous Scene shown before it when pressed. I don't want to create multiple buttons that will lead to a specific scene. – CoolMAn Aug 06 '15 at 19:17
  • In your question you ask to go to scene3 from scene3 ? I'm not sure I fully understand what you're trying to do. – Fred Faust Aug 06 '15 at 19:38
  • @thefredelement Well, I'm trying to create a Button that basically acts as a 'Go Back' button, where it takes me back to the previous Scene I was on before I was sent to the Scene with the UIButton. Just like the back button on a WebBrowser, it doesn't need multiple buttons to take you to certain webpages. It only has a back button to take you to the previous page. Thats what I need, hope that helped – CoolMAn Aug 06 '15 at 20:12

1 Answers1

1

You can use:

self.dismissViewControllerAnimated(true, completion: nil)

To dismiss the current view controller from the view hierarchy.

So you would create an IBAction for your UIButton that would execute that method.

Fred Faust
  • 6,696
  • 4
  • 32
  • 55