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

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


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:

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

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



- (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.

guydor is offline   0 Reply With Quote

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 06:43 PM
Resolved: uipickerview output help. johnnyfla123 iPhone/iPad Programming 12 Jun 20, 2013 12:48 PM
NSUserDefaults(Controller) davidmirv Mac Programming 3 Apr 17, 2013 03:29 PM
Resolved: Need help: UIPIckerView and JSON lasash iPhone/iPad Programming 13 Sep 30, 2012 10:13 AM
NSCoding/NSUserDefaults nashyo iPhone/iPad Programming 5 Jun 25, 2012 05:41 AM

Forum Jump

All times are GMT -5. The time now is 01:15 AM.

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

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