Search code examples
xcodeviewcontroller

Preserve Button State When Switching Between View Controllers


I currently have a navigation controller with 2 view controllers. After clicking Button A on VC 1, it brings me to VC 2. VC 2 has a checklist. When selecting the desired items from the checklist, I am able to select and deselect the checklist buttons. Then I click the back button on VC2 to return to VC 1. When I want to edit the checklist in VC 2, I click Button A to go back to VC 2 but the checklist has reset back to its default state and none of my selections are saved.

I have looked into Model View Controllers, Unwind Segues, UserData, Popping View Controllers but I am still very confused as to what to pick and stick to, for this to work.

Any help is much appreciated. Thanks.


Solution

  • Use UserDefaults for saving information. But remember, use it if the data you are saving are reasonably small (sounds like an array of strings/booleans).

    For learning UserDefaluts go to this link.

    Here are two links 1 & 2 can help you with your problem. Let me know if it is helpful.