David I David I - 8 months ago 319
Swift Question

Xcode 7.2.1 Making a Reset Button using a Button with Swift

I am trying to make a reset button for my app that will reset the UI to the original state. I have made a UIButton and linked it to the ViewController, but I have no idea where to go from here. I tried using the following code:

@IBAction func resetToOriginalState(sender: UIButton) {self.resetToOriginalState (sender: UIButton)}
, but it gave me an "Editor placeholder in source file" error. Please help me!

Sorry if there may be an obvious answer, but I am very new to Swift and Xcode.

Is there any other way to create a reset button? If so, please share.


It depends what is in the scene and what do you need to reload. As far is I know you can't really segue a ViewController to itself, but here are few options:

  1. Try to add loadView() when the button is pressed
  2. Duplicate the view controller, and segue between the two. (might be risky and create more work)
  3. Reset your variables to their initial state when the button is pressed