Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-24-2009, 01:42 AM   #1 (permalink)
New Member
 
Join Date: Feb 2009
Location: Bangkok
Posts: 145
Default 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?
DGYWFT is offline   Reply With Quote
Old 02-24-2009, 01:46 AM   #2 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

are you calling...
Code:
[prefs synchronize];
at the end of your changes?
__________________
I really do this.
Bertrand21 is offline   Reply With Quote
Old 02-24-2009, 01:51 AM   #3 (permalink)
New Member
 
Join Date: Feb 2009
Location: Bangkok
Posts: 145
Default

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];
}
DGYWFT is offline   Reply With Quote
Old 02-24-2009, 01:55 AM   #4 (permalink)
New Member
 
Join Date: Feb 2009
Location: Bangkok
Posts: 145
Default

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...
DGYWFT is offline   Reply With Quote
Old 02-24-2009, 02:18 AM   #5 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

why dont you call this when you are actually changing the intSelection>?
__________________
I really do this.
Bertrand21 is offline   Reply With Quote
Old 02-24-2009, 02:21 AM   #6 (permalink)
New Member
 
Join Date: Feb 2009
Location: Bangkok
Posts: 145
Default

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.
DGYWFT is offline   Reply With Quote
Old 02-24-2009, 02:25 AM   #7 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

what about in the viewDidLoad method?

Code:
-(void)viewDidLoad{
//set prefs code
}
__________________
I really do this.
Bertrand21 is offline   Reply With Quote
Old 02-24-2009, 02:25 AM   #8 (permalink)
New Member
 
Join Date: Feb 2009
Location: Bangkok
Posts: 145
Default

Nevermind, no idea what I did, but works now! haha
DGYWFT is offline   Reply With Quote
Old 02-24-2009, 02:28 AM   #9 (permalink)
New Member
 
Join Date: Feb 2009
Location: Bangkok
Posts: 145
Default

Ps, thanks Bertrand21 for trying to help. It was nice to get some response on here for once.
DGYWFT is offline   Reply With Quote
Old 02-24-2009, 02:28 AM   #10 (permalink)
Beast Mode
 
Join Date: Dec 2008
Age: 21
Posts: 1,890
Default

good deal, and no promblem!
__________________
I really do this.
Bertrand21 is offline   Reply With Quote
Reply

Bookmarks

Tags
nsuserdefaults

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Stats
Members: 158,884
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, karlam963
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:12 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0