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 8268273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T05:49:30+00:00 2026-06-08T05:49:30+00:00

I have 8 textfields in one view. I want to populate each using a

  • 0

I have 8 textfields in one view. I want to populate each using a pickerview.
Can I have 1 pickerview which will display different list of items from different arrays for different textfields?

Can someone explain how do I do it programmatically with a sample code?

Also how can I hide the pickerview when the view loads and it should be displayed only when I click on a textfield with its corresponding data list? It should disappear when I select the data and reappear when I click on a different textfield with its corresponding data list and so on.

I am new to xcode. Any help will be much appreciated. Thank you.

  • 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-06-08T05:49:33+00:00Added an answer on June 8, 2026 at 5:49 am

    You can use only one PickerView that shows different data depending on some conditions.

    My idea is the following: you could create, lets say, 8 different arrays – one for populating the UIPickerView depending on what UITextField was tapped. Declare them in the interface as NSArray and initialize in viewDidLoad:

    array1st = ...
    array2nd = ...
    array3d = ...
    //and until 8.
    

    Then you create another just to point the array that should fill it (like NSArray *currentArray) and you don’t even need to init it = it will be used only for pointing the correct array.

    So you should set the delegate of the UITextFields to your view controller, and in the method textFieldShouldBeginEditing you check who is the UITextField, assign the correct array as the currentArray, reload the UIPickerView with reloadData, and return NO in the same textFieldShouldBeginEditing method. currentTextField is a pointer only to know what is the currentUITextField being “edited” – we need to store it to be able to set the text after selecting data in the picker. Declare currentTextField in the interface.

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    {
        currentTextField = textField;
        if (textField == myFirstTextView)
        {
            currentArray = array1st;
            [pickerView reloadData];
            [self animatePickerViewIn];
            return NO;
        }
        //and this way until 8th
    }
    

    So, when your view controller, that in fact is the UIPickerViewDelegate, you populate your UIPickerView according to the current array and you don’t need to change anything, just use the currentArray as the array to get data from.

    Now, to show the pickerView:

    After connecting the IBOutlet, in your viewDidLoad you should do two things: set the frame of the UIPickerView and add it as a subview:

    pickerView.frame = CGRectMake(0,self.view.frame.size.height, pickerView.frame.size.width, pickerView.frame.size.height);
    pickerView.delegate = self;
    pickerView.dataSource = self;
    //or you can do it via Interface Builder, right click the pickerView and then connect delegate and dataSource to the file's owner
    [self.view addSubview:pickerView];
    

    Now you need to create the method called animatePickerViewIn, that we called when the user taps the UITextField.

    -(void)animatePickerViewIn
    {
    
        [UIView animateWithDuration:0.25 animations:^{
            [pickerView setFrame:CGRectMake(0, pickerView.frame.origin.y-pickerView.frame.size.height, pickerView.frame.size.width, pickerView.frame.size.height)];
        }];
    }
    

    To load the data in the pickerView:

    -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    {
    
        return [currentArray count];
    }
    
    
    -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    {
        return 1;
    }
    
    -(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
    {
        return [currentArray objectAtIndex:row];
    }
    

    And when the user selects the row in the pickerView, you will receive it as a delegate method. So just set the text of the currentTextField as the value selected:

    -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
        //and here you can do in two ways:
        //1
        [currentTextField setText:[currentArray objectAtIndex:row]];
        //2
        [currentTextField setText:[self pickerView:pickerView titleForRow:row inComponent:component]];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pretty Basic one here guys. I have a View which holds 2 textfields for
I have 10 textfields, each of which could hold at most one character. When
I have multiple textfields on my view, and each time a textfield is taped
I have a table view with two rows, each with a text field. One
I have a form(table view) which contains textfields and textview as subviews,I need to
I Have an UITableView with textfields in each row. I want to access these
I have a custom UITableViewCell subclass, and a table view controller which I want
I have a view with 2 textfields in it. The first one should get
In my iPad app I have two textfields. One displays the normal, default textfield
I have created one jsp form which contains the username textfield. On the click

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.