0

Is there a way to "recreate" a UIViewController from within itself. Android SDK 11 added recreate() method to activities. In researching the topic I found this for UI Restoration: UI Restoration

I don't think this is really what I'm looking for.

Basically, my app is a flashcard app which allows the user to retry missed words if they missed any when they finish the deck. In Android it's a simple this.recreate() with missed words stored in SharedPreferences and then reloading the view with the new SharedPreferences field. I have the UserDefaults side of this working. I'm not following if recreating view is possible for iOS. Maybe by segueing out and then back in?

I found this Q&A: stackoverflow link

But I'm not using Navigation Controllers. Just a simple UIViewController.

Thanks for reading!

1 Answers1

0

I presume you want both the view controller's properties and its views to be as before. There's no "magic bullet" for doing that; you just have to do it, yourself.

Now, if your view controller is correctly constructed, its properties automatically dictate its interface. The usual thing, therefore, is just to save off the property values (e.g. in UserDefaults) and later restore them and the interface from that.

It is also possible just to retain the view controller so that you can use it again later, directly. It is, after all, just an ordinary object. This can be a little risky, as the view controller's view is memory-intensive, but there are ways to reduce the amount of memory it occupies.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Would (and is it possible) to segue out from and back into the same VC? What you said is definitely possible, but pretty difficult because I'm tracking a bunch of statistics. I'd have to write an interface for that. Not impossible, just a lot of work. Segueing out and right back in would be easier. Is that poor form? Would it cause memory issues. Or should I just write the interface? – lil_matthew Sep 19 '18 at 19:58
  • I don't know what "segue out from and back into" means. You did not describe the actual situation in any detail in your original question so I don't know what your overall goals are. – matt Sep 19 '18 at 20:13
  • Something like this is what I meant: [link](https://stackoverflow.com/questions/9226983/storyboard-segue-from-view-controller-to-itself) The essence of my question is if there is a proper way to "restart" the UIViewController from within itself (programmatically) so viewWillDisappear, viewDidUnload, dealloc, viewDidLoad, and viewWillAppear are called. I thought maybe if there was a way to get a segue to do this would be easier? – lil_matthew Sep 19 '18 at 20:43
  • I don't really understand what that's about. It would be more helpful if you would explain your actual use case. – matt Sep 19 '18 at 20:48
  • Hey matt, I accepted your answer as "the answer." Basically what you said from the beginning was right. There is no simple command or technique to do what you can do with Android and `recreate()` 'ing an activity. I wrote an interface to my UIViewController last night to handle removing and adding to subviews depending on the logic of what's going on. Thanks! Hopefully this will help someone else out there familiar with Android and learning iOS. This is a fundamental difference between Android and iOS app lifecycles. – lil_matthew Sep 20 '18 at 13:15