Hadi Al Tinawi
Hadi Al Tinawi

Reputation: 429

Recall same UI View controller

I have UI View controller and I want at some point to let it recall it self again so it will re init from the beginning.

How I can do it?

In Android I can do this even if I am already in MyActivity :

StartActivity(typeof(MyActivity)); 

Upvotes: 0

Views: 194

Answers (2)

DonMag
DonMag

Reputation: 77568

Create an "initialize" function:

func myInit() {
    // do my setup
    // set variables to defaults
    // set positions to defaults
    // etc
}

Then, where you currently do all that (often in viewDidLoad):

func viewDidLoad() {
    super.viewDidLoad()
    self.myInit()
}

Then, anytime you want to "re-init", just call myInit() again.

Upvotes: 2

TawaNicolas
TawaNicolas

Reputation: 646

The right way to do this is either to re-initiate all the variables you need to a default value, or to put the view controller inside a container and recreate it every time you want to reset it.

Upvotes: 1

Related Questions