I'm using the ECSlidingViewController to create a slide out menu (like Facebook).
I have this storyboard:
As you can see, I have a navigation controller. I have a major problem though, that even the official demo created by the user who made that controller didn't implement: it doesn't save the state of the view controller when changing views and then coming back.
So, for example, the orange view will always be the first view when I open the app, it gets viewDidLoad
. Then I switch to my green view (the second one), and click the button. It changes the background color of that view to red. Then if I go back to my first view, and then back to the second one, the background color of the latter is green again. I want it to stay red.
This is my code to switch views (in MenuViewController
):
(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Get identifier from selected
NSString *identifier = [NSString stringWithFormat:@"%@", [self.menu objectAtIndex:indexPath.row]];
// Add the selected view to the top view
UIViewController *newTopVC = [self.storyboard instantiateViewControllerWithIdentifier:identifier];
// Present it
[self.slidingViewController anchorTopViewOffScreenTo:ECRight animations:nil onComplete:^{
CGRect frame = self.slidingViewController.topViewController.view.frame;
self.slidingViewController.topViewController = newTopVC;
self.slidingViewController.topViewController.view.frame = frame;
[self.slidingViewController resetTopView];
}];
}
As you can see, it's always instantiating a new VC every time. I want it to save the VC, create the new one if it's not created, then show that one. If the user goes back to a view that has already been created, it should just restore the saved view, not create a new one.
I have put the Init View Controller
in a Navigation Controller, now how can I implement this save/restore mechanism for my views? I'd like it to work with 2,3,4, etc....as many views as possible.
Thanks.