Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 8, 2010, 12:10 PM   #1
guydor
macrumors member
 
Join Date: Mar 2009
UIPickerView and NSUserDefaults issue

Hi,

I have an UIPickerView with 2 components. I would like to save the user's selection and to apply it next time the pickerView is shown again.

Here's my code:

Code:
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults standardUserDefaults];
    [pickerViewSelectionDefaults setInteger:row forKey:@"pickerViewSelectionKey"];
    [pickerViewSelectionDefaults synchronize];

}

}
And...

Code:
- (void)viewWillAppear:(BOOL)animated { 

    NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults standardUserDefaults];
    [pickerView selectRow:[pickerViewSelectionDefaults integerForKey:@"pickerViewSelectionKey"] inComponent:0 animated:YES];

}
The problem is that this NSUserDefaults settings don't save the UIPickerView selections.
My pickerView has 2 components.

Thanks
guydor is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
textfield value not getting saved to nsuserdefaults abcdefg12345 Mac Programming 5 May 8, 2014 07:43 PM
Resolved: uipickerview output help. johnnyfla123 iPhone/iPad Programming 12 Jun 20, 2013 01:48 PM
NSUserDefaults(Controller) davidmirv Mac Programming 3 Apr 17, 2013 04:29 PM
Resolved: Need help: UIPIckerView and JSON lasash iPhone/iPad Programming 13 Sep 30, 2012 11:13 AM
NSCoding/NSUserDefaults nashyo iPhone/iPad Programming 5 Jun 25, 2012 06:41 AM

Forum Jump

All times are GMT -5. The time now is 12:46 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC