I'm trying to learn about data persistence from a book, and I'm using Xcode 4.2 to practice. I'm confused about something and I'm hoping someone out there can help me understand.
In IOS 5, using Xcode 4.2; on an iPhone storyboard, does a modal segue deallocate the view I'm leaving?
If so, why doesn't NSUserDefaults assign the text label in my UIButtons on previous view? I'm forcing NSUserDefaults to synchronise. The UIButton text does eventually populate, when i exist and re-open the application.
NSLogs show that NSUserDefaults are assigned.
Previous View
the following generate*options methods call for an NSArray to be generated, which is then passed to the picker in the modal view when a button is pressed.
In IOS 5, using Xcode 4.2; on an iPhone storyboard, does a modal segue deallocate the view I'm leaving?
If so, why doesn't NSUserDefaults assign the text label in my UIButtons on previous view? I'm forcing NSUserDefaults to synchronise. The UIButton text does eventually populate, when i exist and re-open the application.
Code:
- (void) saveCardiacString:(NSString *) myString
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] setObject:myString forKey:@"Cardiac"];
[userDefaults synchronize];
}
Code:
- (void) saveRespiratoryString:(NSString *) myString
{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[[NSUserDefaults standardUserDefaults] setObject:myString forKey:@"Respiratory"];
[userDefaults synchronize];
}
Code:
- (void)pickerView:(UIPickerView *)pickerView
didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
if ([[_currentOptions objectAtIndex:0] isEqualToString:@"no cardiac failure"]) {
[self saveCardiacString:[_currentOptions objectAtIndex:row]];
} else if ([[_currentOptions objectAtIndex:0] isEqualToString:@"no dyspnoea"]) {
[self saveRespiratoryString:[_currentOptions objectAtIndex:row]];
}
NSLog(@"Cardiac string is set as %@", [self retrieveCardiacStringValue]);
NSLog(@"Respiratory string is set as %@", [self retrieveRespiratoryStringValue]);
}
NSLogs show that NSUserDefaults are assigned.
Previous View
Code:
- (NSString *) retrieveCardiacStringValue
{
return [[NSUserDefaults standardUserDefaults] objectForKey:@"Cardiac"];
}
Code:
- (NSString *) retrieveRespiratoryStringValue
{
return [[NSUserDefaults standardUserDefaults] objectForKey:@"Respiratory"];
}
the following generate*options methods call for an NSArray to be generated, which is then passed to the picker in the modal view when a button is pressed.
Code:
- (void)viewDidLoad
{
_currentCardiacOptions = [Cardiac generateCardiacOptions];
_currentRespiratoryOptions = [Respiratory generateRespiratoryOptions];
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"Cardiac"] == nil) {
[_cardiacValueBtn setTitle:@"0" forState:UIControlStateNormal];
} else {
[_cardiacValueBtn setTitle:[self retrieveCardiacStringValue] forState:UIControlStateNormal];
}
if ([[NSUserDefaults standardUserDefaults] objectForKey:@"Respiratory"] == nil) {
[_respriatoryValueBtn setTitle:@"0" forState:UIControlStateNormal];
} else {
[_respriatoryValueBtn setTitle:[self retrieveRespiratoryStringValue] forState:UIControlStateNormal];
}
[super viewDidLoad];
}