DaniLG
DaniLG

Reputation: 23

How can I keep viewcontroller in memory

I am developing an app in Swift 3.0 with this hamburger menu like in the picture.

So, in my menu item1, I have a tableView that loads information from my server and populates the table. when I select another viewController from the slide out menu and go back to my item1. It loads again the tableView and take some time to load (naturally).

My question is, How can i keep my item1 in memory and not have to load the tableView again each time I want to open this menuitem1VC. The perfect way to load this tableView would be each time I open my app but I can't figure it out.

Upvotes: 0

Views: 540

Answers (2)

Łukasz Przytuła
Łukasz Przytuła

Reputation: 575

I'd use the UITabBarController with hidden tab bar

tabBarController.tabBar.isHidden = true

And on selecting the hamburger menu items, I'd programmatically change tab, i.e. when hamburger menu item at index 2 was selected:

tabBarController.selectedIndex = 2

It covers all viewWillAppear / viewDidAppear calls, so you wouldn't have to implement all that logic.

Upvotes: 1

Vishal Sonawane
Vishal Sonawane

Reputation: 2693

You can follow this approach:

1) For the first time when you select your menu item, fetch data from server and store in either DB or somewhere else.

2) When you second time click the same item, first check if the data for that item is available locally or not.

3) It its available ,simply use it otherwise you will have to fetch again from web service.

Upvotes: 1

Related Questions