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

  • Home
  • SEARCH
  • 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 8304523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:52:14+00:00 2026-06-08T17:52:14+00:00

I can get a text box value from a picker to one text box.

  • 0

I can get a text box value from a picker to one text box. How do I get a different values to more text boxes. At present all the text fields get filled even if im only filling out one text box and only display the values from first NSArray. I tried an if statement, Apple documentation not much help.

I have no idea how tagging works but noted it was mentioned when researching this. Apologies if I haven’t explained this properly heres a test app to download if I havnt made much sense that explains it better

APP example

.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIPickerViewDataSource,    UIPickerViewDelegate,UITextFieldDelegate>

{
//decalre picker
UIPickerView *select;



//declare NSArrray
NSArray *arrStatus;
NSArray *arrStatus2;


 }

@property (strong, nonatomic) IBOutlet UITextField *text1;
 - (IBAction)Value:(id)sender;
@property (strong, nonatomic) IBOutlet UITextField *text2;
@end

.m

     - (void)viewDidLoad
 {



///create picker//////////////////////////////////////////////////////////////////////////

select = [[UIPickerView alloc] initWithFrame:CGRectZero];
select.delegate = self;
select.dataSource = self;
[select setShowsSelectionIndicator:YES];
text1.inputView = select;
text2.inputView = select;



////arrays & objects
arrStatus = [[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",nil];
arrStatus2 = [[NSArray alloc] initWithObjects:@"A",@"B",@"C",@"D",nil];

//number of colums and rows etc of picker    
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
//One column
return 1;
}

 -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component
{
//set number of rows
return arrStatus.count;
 return arrStatus2.count;

  }

  -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
 {
//set item per row
return [arrStatus objectAtIndex:row];
return [arrStatus2 objectAtIndex:row];


- (IBAction)Value:(id)sender {

///get picker values to text field
NSInteger selectedRow = [select selectedRowInComponent:0];

text1.text = [arrStatus objectAtIndex: selectedRow];
[text1 resignFirstResponder];

text2.text = [arrStatus2 objectAtIndex: selectedRow];
[text2 resignFirstResponder];


 }

 @end
  • 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-08T17:52:16+00:00Added an answer on June 8, 2026 at 5:52 pm

    in the method for didselectrow I had my if statement see which text field was the first responder. Then used the following code. It places the uipicker value in each of the text fields.

    -(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
    if ([_input1 isFirstResponder])
    {
        NSString *resultString1 = [[NSString alloc] initWithFormat:[gradeArray objectAtIndex:[pickerView selectedRowInComponent:0]]];
        NSString *resultString2 = [[NSString alloc] initWithFormat:[plusMinusArray objectAtIndex:[pickerView selectedRowInComponent:1]]];
        NSString *gradeResult = [resultString1 stringByAppendingString:resultString2];
        _input1.text = gradeResult;
    }else if ([_input2 isFirstResponder])
    {
        NSString *resultString1 = [[NSString alloc] initWithFormat:[gradeArray objectAtIndex:[pickerView selectedRowInComponent:0]]];
        NSString *resultString2 = [[NSString alloc] initWithFormat:[plusMinusArray objectAtIndex:[pickerView selectedRowInComponent:1]]];
        NSString *gradeResult = [resultString1 stringByAppendingString:resultString2];
        _input2.text = gradeResult; 
    }else if ([_inputM isFirstResponder])
    {
        NSString *resultString1 = [[NSString alloc] initWithFormat:[gradeArray objectAtIndex:[pickerView selectedRowInComponent:0]]];
        NSString *resultString2 = [[NSString alloc] initWithFormat:[plusMinusArray objectAtIndex:[pickerView selectedRowInComponent:1]]];
        NSString *gradeResult = [resultString1 stringByAppendingString:resultString2];
        _inputM.text = gradeResult;
    }else if ([_input3 isFirstResponder])
    {
        NSString *resultString1 = [[NSString alloc] initWithFormat:[gradeArray objectAtIndex:[pickerView selectedRowInComponent:0]]];
        NSString *resultString2 = [[NSString alloc] initWithFormat:[plusMinusArray objectAtIndex:[pickerView selectedRowInComponent:1]]];
        NSString *gradeResult = [resultString1 stringByAppendingString:resultString2];
        _input3.text = gradeResult;
    }else if ([_input4 isFirstResponder])
    {
        NSString *resultString1 = [[NSString alloc] initWithFormat:[gradeArray objectAtIndex:[pickerView selectedRowInComponent:0]]];
        NSString *resultString2 = [[NSString alloc] initWithFormat:[plusMinusArray objectAtIndex:[pickerView selectedRowInComponent:1]]];
        NSString *gradeResult = [resultString1 stringByAppendingString:resultString2];
        _input4.text = gradeResult;
    }
    }
    

    Hope this helps.

    EDIT

    if you want to get both arrays in the picker, you need to make the columns 2. This will show both arrays. I used the following code to display both my arrays in the picker view.

    -(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
    {
    return 2;
    }
    
    -(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    {
    if (component == 0)
    {
        return [gradeArray count];
    }
    return [plusMinusArray  count];
    }
    
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
    {
    if (component == 0)
    {
        return  [gradeArray objectAtIndex:row];
    }
    return [plusMinusArray objectAtIndex:row];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to get the value from one text box and add
How can I get the text value from an elements's child? Say I have
How can I get the selected text (not the selected value) from a drop-down
My question is, how can I get text from header in javascript? So if
How can I get the text value of a segment in a UISegmentedControl?
Can any guru show me how to get values from HTML Form element -
I have no problem getting a value from a text box with some id:
I'm wondering how I can populate a text box in my view from a
I am trying to get the value from the radio boxes/button with php. The
Hi all I have written the following script to get the value from the

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.