zaam zaam - 6 months ago 32
iOS Question

Preserving a view on return navigation

I'm trying to create a music player application that plays audio files. I've managed to create the player but when I navigate back (or dismiss it), the view state is lost, though the control centre player is still playing the audio. Now when I make any attempts to go back to the player, the view loads all over again and two audios play simultaneously (from different starting points of course). I believe the problem is I'm not preserving the view when dismissing it. One way I thought was to keep track of all changes and load the view with the 'preserved' settings but since this is a music player, there are too many things to keep track of. So my question is:

  1. Is there a better strategy to preserve the view state? (I've tried to hide and the screen goes black and I somehow don't get how to use container views)

  2. And more importantly, how can I minimize my player and let the user navigate around and allow him/her to return to the player without affecting the experience.


The solution was to create and attach a subview that persists and then dismiss the subview from the superview whenever you're done using it.