Is there a way to avoid viewDidLoad beeing called after every segue?

后端 未结 2 1596
说谎
说谎 2021-01-23 07:09

i initialize tables, data etc in my main ViewController. For more settings, i want to call another Viewcontroller with:

 DateChangeController *theController = [s         


        
2条回答
  •  日久生厌
    2021-01-23 07:54

    The problem is that you are doing this:

    main view controller ->
        date change controller ->
            a *different* main view controller
    

    In other words, although in your verbal description you use the words "returning to my main ViewController", you are not in fact returning; you are moving forward to yet another instance of this main view controller every time, piling up all these view controllers on top of one another.

    The way to return to an existing view controller is not to make a segue but to return! The return from presentViewController is dismissViewController. You do not use a segue for that; you just call dismissViewController. (Okay, in iOS 6 you can in fact use a segue, but it is a very special and rather complicated kind of segue called an Unwind or Exit segue.)

    If you do that, you'll be back at your old view controller, which was sitting there all along waiting for your return, and viewDidLoad will not be called.

    So, this was a good question for you to ask, because the double call of viewDidLoad was a sign to you that your architecture was all wrong.

提交回复
热议问题