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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:41:30+00:00 2026-06-19T00:41:30+00:00

I have created two UITextFields and want to create two different UIPickerViews for both

  • 0

I have created two UITextFields and want to create two different UIPickerViews for both the textFields with different values and how to map the individual textFields to each pickerView specifically?
any help ?

  • 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-19T00:41:31+00:00Added an answer on June 19, 2026 at 12:41 am

    First of all create two array that contain different value that you want to display in the diff picker, we say aray1 and ary2 .

    Now add this in .h file

      @interface YourViewController : UIViewController<UITextFieldDelegate,UIPickerViewDelegate, UIPickerViewDataSource>
        {
    
            UIToolbar* keyboardDoneButtonView;
            UIPickerView *pickerView;
            NSString * txtFieldSelected;
            NSArray *ary2;
            NSArray *ary1;
        }
    

    And in .h file

     - (void)viewDidLoad
    
            {
                [super viewDidLoad];
                firstTF.delegate = self;
                secondTF.delegate = self;
                ary1 =[NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8", nil];
               ary2 =[NSArray arrayWithObjects:@"a",@"s",@"d",@"f",@"g",@"h",@"x",@"c", nil];
            }
    
    -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    
            if (textField == firstTF) {
                txtFieldSelected = @"firstTF";
            }else if (textField == secondFF) {
                txtFieldSelected = @"secondTF";
            }
            CGRect pickerFrame = CGRectMake(0, 40, 0, 0);  
    
            pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];  
            pickerView.showsSelectionIndicator = YES;  
            pickerView.dataSource = self;  
            pickerView.delegate = self;  
    
            keyboardDoneButtonView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];  
            keyboardDoneButtonView.barStyle     = UIBarStyleBlackTranslucent;  
            [keyboardDoneButtonView sizeToFit];  
    
            NSMutableArray *barItems = [[NSMutableArray alloc] init];
    
            UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelButtonPressed:)];  
            [barItems addObject:cancelBtn];  
    
            UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];  
            [barItems addObject:flexSpace];  
    
            UIBarButtonItem *doneBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneButtonPressed:)];  
            [barItems addObject:doneBtn];  
    
    
            [keyboardDoneButtonView setItems:barItems animated:YES]; 
            textField.inputAccessoryView = keyboardDoneButtonView;
    
            textField.inputView = pickerView;
    
    
        return YES;
    }
    
    
    -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    {
        return 1;
    }
    
    
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
    {
        if (txtFieldSelected == @"firstTF") {
            return ary1.count;
        }else if (txtFieldSelected == @"secondTF") {
            return ary2.count;
        }
        return 1;
    
    }
    
    -(void)doneButtonPressed:(id)sender{  
        if (txtFieldSelected == @"firstTF") {
            [firstTF resignFirstResponder];
    
        }else if (txtFieldSelected == @"secondTF") {
    
            [secondTF resignFirstResponder];
        }
    }  
    
    -(void)cancelButtonPressed:(id)sender{ 
    
        if (txtFieldSelected == @"firstTF") {
            [firstTF resignFirstResponder];
    
        }else if (txtFieldSelected == @"secondTF") {
            [secondTF resignFirstResponder];
    
        }
    }  
    
    
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row inComponent:(NSInteger)component {
        // called when a row is selected
    
        if (txtFieldSelected == @"firstTF") {
    
            firstTF.text = [ary1 objectAtIndex:row];
        }else if (txtFieldSelected == @"secondTF") {
            secondTF.text = [ary2 objectAtIndex:row];
    
        }
    
    }
    
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
        if (txtFieldSelected == @"firstTF") {
            return [ary1 objectAtIndex:row];
        }else if (txtFieldSelected == @"secondTF") {
            return [ary2 objectAtIndex:row];
        }
    
        return @"Good Day";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created two WindowSurface (WPF), and I want to navigate betwen them. I've
I have created two tables & inserted values as shown below . Table 1
I have created two comboboxes. I have to create a match the following program,
I have created two different iPhone application with two different push notification certificate, when
I have created two models :User and UserProfile , Now I want display in
I have created two classes, actually both of them extends Activity. What I am
I am working on scrapy, i have created two spider files with two different
I have created two menus, a horizontal drop-down and a vertical menu, these both
I am trying to do the login form I have created two uitextfields for
I have created two views in sqlite - android , but when i create

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.