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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:24:21+00:00 2026-06-11T15:24:21+00:00

I got a Problem with a Picker View in Xcode 4.4. I want to

  • 0

I got a Problem with a Picker View in Xcode 4.4. I want to populate 1 Picker with multiple arrays. I watched / read a lot of tutorials and could get almost to work. This is my code:

*.h

 #import <UIKit/UIKit.h>

@interface PickerView : UIViewController

<UIPickerViewDataSource,UIPickerViewDelegate>
{
    IBOutlet UIPickerView *picker;

    NSMutableArray *array_1;
    NSMutableArray *array_2;
}

@property (strong, nonatomic) IBOutlet UIView *pickerContainer;
@property (strong, nonatomic) IBOutlet UITextField *textfield_1;
@property (strong, nonatomic) IBOutlet UITextField *textfield_2;

- (IBAction)showArray_1Picker:(id)sender;
- (IBAction)showArray_2Picker:(id)sender;
- (IBAction)hidePicker:(id)sender;

@end

*.m

#import "PickerView.h"

@interface PickerView ()

@end

@implementation PickerView
@synthesize pickerContainer;
@synthesize textfield_1;
@synthesize textfield_2;

int textFieldTouched = 0;

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)picker
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent (NSInteger)component
{
    switch(textFieldTouched)
    {
        case 1:
            return [array_1 count];
            break;
        case 2:
            return [array_2 count];
            break;
        default:
            return 0;
    }
}


- (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    switch(textFieldTouched)
    {
        case 1:
            return [array_1 objectAtIndex:row];
            break;
        case 2:
            return [array_2 objectAtIndex:row];
            break;
        default:
            return @"nothing";
    }
}

- (void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    switch(textFieldTouched)
    {
        case 1:
            textfield_1.text = [array_1 objectAtIndex:[pickerView selectedRowInComponent:0]];
            break;
        case 2:
            textfield_2.text = [array_2 objectAtIndex:[pickerView selectedRowInComponent:0]];
            break;
    }
}

 - (void)viewDidLoad
 {
    array_1 = [[NSMutableArray alloc] init];
    [array_1 addObject:@"1"];
    [array_1 addObject:@"2"];
    [array_1 addObject:@"3"];
    [array_1 addObject:@"4"];
    [array_1 addObject:@"5"];

    array_2 = [[NSMutableArray alloc] init];
    [array_2 addObject:@"a"];
    [array_2 addObject:@"b"];
    [array_2 addObject:@"c"];
    [array_2 addObject:@"d"];
    [array_2 addObject:@"e"];

    pickerContainer.frame = CGRectMake(0, 460, 320, 261);

    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [self setPickerContainer:nil];
    [self setTextfield_1:nil];
    [self setTextfield_2:nil];
    [super viewDidUnload];
}

- (IBAction)showArray_1Picker:(id)sender
{
    [textfield_1 resignFirstResponder];
    textFieldTouched = 1;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    pickerContainer.frame = CGRectMake(0, 200, 320, 261);
    [UIView commitAnimations];
}

- (IBAction)showArray_2Picker:(id)sender
{
    [textfield_2 resignFirstResponder];
    textFieldTouched = 2;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    pickerContainer.frame = CGRectMake(0, 200, 320, 261);
    [UIView commitAnimations];
}

- (IBAction)hidePicker:(id)sender
{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];
    pickerContainer.frame = CGRectMake(0, 460, 320, 261);
    [UIView commitAnimations];
}

@end

So i got 2 main problems:

  1. If i set textFieldTouched = 0 (or > 2) like i did before my picker is empty when it shows up. Anyway if I hide it again it writes the first value of the corresponding array in the textfield.

  2. If i set textFieldTouched = 1 or =2 the picker is populated with the related array no matter what text field I try to edit. But if I scroll the values on the picker out of my sight they have changed when i scroll back.

I want to have it like this:

If i touch text field 1 the picker shows up populated with array 1

If i touch text field 2 the picker shows up populated with array 2

ans so on.

Can u help me with that?

I’ve uploaded the code so you can look at it better.

https://dl.dropbox.com/u/5858884/ProblemCode.zip

P.S.

English is not my mother language so please excuse mistakes 😉

I started programming 2 weeks ago, so if u find something wrong in my code that doesnt belong to my problem please tell me so I can get better 🙂

  • 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-11T15:24:22+00:00Added an answer on June 11, 2026 at 3:24 pm

    In your showArray1Picker and showArray2Picker methods add the line:

    [picker reloadAllComponents];
    

    This will cause the picker to reload its data. You also need to connect the IBOutlet, picker, to the picker view in IB — I noticed that it was not connected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got problem with DirectX in C#. I want to draw some lines. Firstly
I've got problem for my application. I want to start connectbot from my application
I want to ask about strcpy. I got problem here. Here is my code:
got a problem, can't get my head around this jquery and would appreciate your
I'm creating an application with Swing , and I've got a problem. I want
I've got a view when I want to use UIPickerView but my application supports
i got problem with my code and hopefully someone able to figure it out.
I got problem with sending data in Android using httpPost. I found some example,
I've got problem with connecting to MySQL database on my freshly installed Windows 7
have a nice day. I got problem when trying to create an image from

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.