AAV AAV - 1 year ago 57
iOS Question

Saving state for presentModalViewController in iOS application

I am creating a application where I require a filter button. When I click on filter button, ModalViewController will pop from the bottom of the screen.

[self presentModalViewController:filterActivity animated:YES];

When I am done with that filter screen I am dismissing it with

[self dismissModalViewControllerAnimated:YES];

Now problem is when I dismissModalViewController then all the date entered in UITextField is gone. Is there any way to save the data or save the state of presentModalViewController ?

Answer Source

I solve the problem. By using Singleton pattern I have solve the problem. Now I can see data in text filed or label even if i dismiss the modalviewcontroller and come back again. Code for Singleton

+ (MNActivityFilter *) sharedManager {
static dispatch_once_t once;
static MNActivityFilter *sharedManager;
dispatch_once(&once, ^ { sharedManager = [[MNActivityFilter alloc] init]; });
return sharedManager;