02-24-2009, 01:42 AM
#1 (permalink )
New Member
Join Date: Feb 2009
Location: Bangkok
Posts: 145
NSUserDefaults and changing views
I haven't gotten a response on this forum on my past 3 posts, so I assume this is my last attempt here, haha.
I am using NSUserDefaults to set one simple preference, and its all working and setting the value. My problem is though when I set the preference and flip back to my main view, the preference value doesn't update on main view. The only way to reset the value on the front view is to restart the app.
Anyone ever had this problem?
02-24-2009, 01:46 AM
#2 (permalink )
Beast Mode
Join Date: Dec 2008
Age: 21
Posts: 1,890
are you calling...
Code:
[prefs synchronize];
at the end of your changes?
__________________
I really do this.
02-24-2009, 01:51 AM
#3 (permalink )
New Member
Join Date: Feb 2009
Location: Bangkok
Posts: 145
Yup! Here and also on another action.
- (void)viewWillDisappear {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int test = [domainPicker selectedSegmentIndex];
[defaults setObject:[NSString stringWithFormat:@"%d",test] forKey:@"Domain"];
[defaults synchronize];
}
02-24-2009, 01:55 AM
#4 (permalink )
New Member
Join Date: Feb 2009
Location: Bangkok
Posts: 145
It seems when I come back to the front view (from the prefs view), the view wont update. For example I try to call:
- (void) viewWillAppear{
[NSUserDefaults resetStandardUserDefaults];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
int valueMe = [prefs integerForKey:@"Domain"];
NSLog(@"num = %i", valueMe);
}
But nothing runs...
02-24-2009, 02:18 AM
#5 (permalink )
Beast Mode
Join Date: Dec 2008
Age: 21
Posts: 1,890
why dont you call this when you are actually changing the intSelection>?
__________________
I really do this.
02-24-2009, 02:21 AM
#6 (permalink )
New Member
Join Date: Feb 2009
Location: Bangkok
Posts: 145
I do that also in the prefs page:
- (IBAction) pickDomain: (id) sender {
// Get Default Settings
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int test = [domainPicker selectedSegmentIndex];
[defaults setObject:[NSString stringWithFormat:@"%d",test] forKey:@"Domain"];
[defaults synchronize];
}
The issue seems the front view isn't updating at all. It loads, but doesn't refresh after i flip the view.
02-24-2009, 02:25 AM
#7 (permalink )
Beast Mode
Join Date: Dec 2008
Age: 21
Posts: 1,890
what about in the viewDidLoad method?
Code:
-(void)viewDidLoad{
//set prefs code
}
__________________
I really do this.
02-24-2009, 02:25 AM
#8 (permalink )
New Member
Join Date: Feb 2009
Location: Bangkok
Posts: 145
Nevermind, no idea what I did, but works now! haha
02-24-2009, 02:28 AM
#9 (permalink )
New Member
Join Date: Feb 2009
Location: Bangkok
Posts: 145
Ps, thanks Bertrand21 for trying to help. It was nice to get some response on here for once.
02-24-2009, 02:28 AM
#10 (permalink )
Beast Mode
Join Date: Dec 2008
Age: 21
Posts: 1,890
good deal, and no promblem!
__________________
I really do this.
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
» Advertisements
» Online Users: 318
24 members and 294 guests
@sandris , ADY , BrianSlick , dacapo , Dani77 , Dattee , dre , HDshot , HemiMG , JasonR , karlam963 , MarkC , mer10 , nibeck , prchn4christ , Rudy , ryandb2 , spiderguy84 , themathminister , timle8n1 , tomtom100 , viniciusdamone , vogueestylee , vvenkatachallam
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963