1

Project desc.

I have a left drawer with a table selection with many options. One of which is a settings option.

Inside the settings option is a table view. I have embedded AKPickerView inside once of the cells. The AKPickerView is giving me the option to choose which animation the user want's to use through out the app.

Everything is being displayed properly, however, when selecting the animation, and reopening the settings view, the picker resets itself.

Below is how it's set up.

cellForRowAtIndexPath:

            //Animation Picker
            self.pickerView = [[AKPickerView alloc] initWithFrame:cell.bounds];
            self.pickerView.delegate = self;
            self.pickerView.dataSource = self;
            self.pickerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
            [cell addSubview:self.pickerView];

            self.pickerView.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:20];
            self.pickerView.highlightedFont = [UIFont fontWithName:@"HelveticaNeue" size:20];
            self.pickerView.interitemSpacing = 25.0;
            self.pickerView.fisheyeFactor = 0.0002;
            self.pickerView.pickerViewStyle = AKPickerViewStyle3D;

            zoom = @"Zoom Out";
            drop = @"Drop In";
            push = @"Push";

            self.titles = @[zoom, drop, push];

            [self.pickerView reloadData];

Count, title and didSelect:

- (NSUInteger)numberOfItemsInPickerView:(AKPickerView *)pickerView {
    return [self.titles count];
}

- (NSString *)pickerView:(AKPickerView *)pickerView titleForItem:(NSInteger)item {
    return self.titles[item];
}

- (void)pickerView:(AKPickerView *)pickerView didSelectItem:(NSInteger)item {

    if ([self.titles[item] isEqual:zoom]) {
        [[NSUserDefaults standardUserDefaults] setObject:@"Zoom Out" forKey:@"Zoom"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }

    else if ([self.titles[item] isEqual:drop]) {
        [[NSUserDefaults standardUserDefaults] setObject:@"Drop In" forKey:@"Drop"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }

    else if ([self.titles[item] isEqual:push]) {
        [[NSUserDefaults standardUserDefaults] setObject:@"Push" forKey:@"Push"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }

    NSLog(@"%@", self.titles[item]);
}

How can I make the picker save the scroll location or save the selected item, so when I reopen the view it stayed put?

Any help would be appreciated.

ChrisOSX
  • 724
  • 2
  • 11
  • 28

2 Answers2

2

If you want the data to remain still while using the app and that when you close it it won't matter, you should use persistance (iOS: Saving a double picker's settings (data persistence)). But if you want it to remain (the data) no matter what you should use core data.

Community
  • 1
  • 1
0

Thanks to the dev, I managed to get this working with the code below:

What I had to do was move this to the viewDidLoad:

//Picker Titles
zoom = @"Zoom Out";
drop = @"Drop In";
push = @"Push";
self.titles = @[zoom, drop, push];

cellForRowAtIndexPath:

[self.pickerView selectItem:[[NSUserDefaults standardUserDefaults] integerForKey:kAnimationTypeKey] animated:false];

and (AKPickerView *)pickerView didSelectItem:

[[NSUserDefaults standardUserDefaults] setInteger:item forKey:kAnimationTypeKey];

This got me to to reload the view and keep the selected item...so far :)

Now I just need to figure out how to save the user defaults properly per key.

ChrisOSX
  • 724
  • 2
  • 11
  • 28