Don't destroy view after navigating

Viewed 432

I have some view (let's name it View A), which contains list of items. After tapping particular item, it navigates user to view with details (View B). List in view A is very long, so I would like to keep scroll position and list rendered for user when back button in View B is clicked. For now, when back button in View B is clicked, View A is loaded as new view. Is there some convenient way to achieve this? Also, how this view could be destroyed manually, if user will go anywhere else fro View B?

Navigating from A to B is achieved with:

NavigationLink(destination: DetailsView(), isActive: $redirectToDetails) { EmptyView() }

Navigating from B to A is achieved with default swift back button.

Edit 1: enter image description here

Step 1: User scrolls list down and taps some position, which navigates to Details view

Step 2: User is in details view and clicks back button

Step 3: User is navigated back to list view, list view performs data load and list is scrolled to top.

I want to persist rendered view (from step 1) in some way, so when users comes back to it data is not loaded again and list scroll position is exactly the same as it was when navigation to details view was performed.

1 Answers

I think you are fetching data in view A in viewWillAppear or viewDidAppear method or/and you are doing reloading of your tableView on viewWillAppear or viewDidAppear. If you move this fetching and reloading tableview code to viewDidLoad() then your issue will be fixed.

Related