Reputation: 145
I have set up a Tab Bar that controls some view controllers in my app. In my view controller CheckViewController, I have user entry-based data that I would like to save every time I am switching from CheckViewController to another view controller. The code I have currently only saves data the first time I switch from CheckViewController to another view controller using the tab bar. I would like to save data every single time CheckViewController is opened and switched to another view controller.
I am currently using:
- (void)viewDidLoad {
[super viewDidLoad];
self.tabBarController.delegate = self;
//code
}
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
if (![viewController isEqual:self]) {
if ([self.tabBarController.selectedViewController isEqual:self] ) {
//save data
}
}
return YES;
}
Suggestions are appreciated. Thanks!
Upvotes: 1
Views: 75
Reputation: 1207
for saving small data,you can use NSUserDefault. here is an example for saving and reading data.
Save:
[[NSUserDefaults standardUserDefaults] setObject:aData forKey:aKey];
[[NSUserDefaults standardUserDefaults] synchronize];
Read:
[[NSUserDefaults standardUserDefaults] objectForKey:aKey];
Upvotes: 1