I display a modal view controller and from there use buttons to add subviews. I need to add other view controllers as subviews, and then remove the one behind it. So can I reference the views by their index?
Practical example: User sees page 1 (The root view controller) User presses button which adds a subview, page 2. User presses another button which adds a subview, page 3. Now I need to remove page 2 so as not to consume memory and have things going on back there.
It's not as simple as removing it by name, because my root view controller has next/back buttons and buttons to specific views. I can always insert the right "next" subview but the one to remove could be any of them. The user could be on page 2, 3, 4 etc and jump to page 5. In the button action for page 5 I can of course add the page 5 view controller as a subview, but how do I tell it to remove the last subview when it could be any of them?