0

Using storyboards, I have a button that modally presents a UINavigationController (with a UITableViewController as the root) that allows the user select rows to push additional views on the stack. The user can navigate down a hierarchy until they find the item they want. Selecting an item or swiping down closes the modal view.

If the user presses the button again, I would like to display the view with the same state as it was when it was previously closed (ie, opened with the same set of views pushed on the stack). Is it possible to hold on to the view when it closes and reuse it, or is there another way to maintain the state?

I looked into state preservation, but I don't want the state preserved if the app is closed and reopened, and I'm not sure it will handle this case in any event (at least, my attempt at implementing it didn't work).

1
  • If you don't want the state to live past the app closure, you can discard this via the AppDelegate or SceneDelegate Commented Sep 8, 2024 at 22:10

1 Answer 1

1

Check apple docs SetViewControllers

You can access the viewControllers property on UINavigationController to get the view controllers on the stack and save them to a local property.

Sign up to request clarification or add additional context in comments.

1 Comment

This was just what I needed. In the navigation controllers viewDidLoad I set any previously saved view controllers, and saved the view controllers in viewWillDisappear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.