Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5845549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:27:02+00:00 2026-05-22T12:27:02+00:00

I have pickerView with two rows and I need to save position of both

  • 0

I have pickerView with two rows and I need to save position of both to NSUserDefaults. I have successful saved first row with this code:

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {    
    NSInteger selectedRow = [thePickerView selectedRowInComponent:0];

    [[NSUserDefaults standardUserDefaults] setInteger:selectedRow forKey:@"picker"];
}

And I don’t get how to add a second one.

With this code I bring back the position:

-(void)viewWillAppear: (BOOL) animated {
    NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults standardUserDefaults];
[picker selectRow:[pickerViewSelectionDefaults integerForKey:@"picker"] inComponent:0 animated:YES];
[picker selectRow:[pickerViewSelectionDefaults integerForKey:@"picker"] inComponent:1 animated:YES];
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:27:03+00:00Added an answer on May 22, 2026 at 12:27 pm

    Try this:

    - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row
                 inComponent:(NSInteger)component {    
        NSInteger selectedRow = [thePickerView selectedRowInComponent:component];
        NSString *key = [NSString stringWithFormat:@"picker%d", component];
    
        [[NSUserDefaults standardUserDefaults] setInteger:selectedRow forKey:key];
    }
    

    and this

    -(void)viewWillAppear: (BOOL) animated {
        NSUserDefaults *pickerViewSelectionDefaults = [NSUserDefaults standardUserDefaults];
        [picker selectRow:[pickerViewSelectionDefaults integerForKey:@"picker0"] 
            inComponent:0 animated:YES];
        [picker selectRow:[pickerViewSelectionDefaults integerForKey:@"picker1"] 
            inComponent:1 animated:YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have UIPickerView with two rows. Trying to save value of each row in NSUserDefaults
I have the following code that should change the selected rows in two different
I have two columns pickerView. In first column i have units like km, feet.
I have got a UIPickerView. When I select a row, this happens: - (void)pickerView:(UIPickerView
have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have the following code to create a UIPickerView: pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0f,
I have a custom UIPickerView where I use: -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView
I have 3 UITexfield, the user can fill in the first two, but the
i have added a pickerview from interface builder.i am using this method to show
I have a picker with three components. The first two components are dependent on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.