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

The Archive Base Latest Questions

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

I am using textFields inputView property to display UIPickerViews instead of the keyboard. The

  • 0

I am using textFields inputView property to display UIPickerViews instead of the keyboard. The way I have it programmed, I do not declare the PickerViews in the .H file, or connect them in the view in interface builder. When I implement the properties of the pickerviews, I am not able to make each of them with different properties. I tried using “if” statements to tell it to have different properties depending on which picker was being used like follows….

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)agePickerView {
    if ([pickerView isEqual: agePickerView]){
                 return 1;
    }
            if ([pickerView isEqual: weightPickerView]){
                 return 1;
    }

}

When I do this though, It will say that weightPickerView is undeclared. So here is my code for implementing the pickerViews.

@implementation MainViewController

//WEIGHT FIELD CODE 

-(IBAction)weightFieldDidBeginEditing{
UIPickerView *weightPickerView = [[UIPickerView alloc] init];
weightField.inputView = weightPickerView;
weightPickerView.showsSelectionIndicator = YES;
weightPickerView.delegate = self;
weightPickerView.dataSource = self;
[weightPickerView release];

UIToolbar *weightToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]   initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked:)];
[weightToolBar setItems:[NSArray arrayWithObject:doneButton] animated:NO];
 weightField.inputAccessoryView = weightToolBar;
}

-(NSInteger)weightpickerView:(UIPickerView *)weightPickerView numberOfRowsInComponent: (NSInteger)component{
return [weightPickerArray count];
}

-(NSString *)weightpickerView:(UIPickerView*)weightPickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [weightPickerArray objectAtIndex:row];
}

// AGE FIELD CODE

-(IBAction)ageFieldDidBeginEditing{
UIPickerView *agePickerView = [[UIPickerView alloc] init];
ageField.inputView = agePickerView;
agePickerView.showsSelectionIndicator = YES;
agePickerView.delegate = self;
agePickerView.dataSource = self;
[agePickerView release];

UIToolbar *ageToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked:)];
[ageToolbar setItems:[NSArray arrayWithObject:doneButton] animated:NO];
ageField.inputAccessoryView = ageToolbar; 
}

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

-(NSInteger)pickerView:(UIPickerView *)agePickerView numberOfRowsInComponent: (NSInteger)component {
return [agePickerArray count];
}

-(NSString *)pickerView:(UIPickerView*)agePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [agePickerArray objectAtIndex:row];

}

-(void)pickerView:(UIPickerView *)agePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    ageField.text = (NSString *) [agePickerArray objectAtIndex:row];
}

-(void)pickerDoneClicked:(id)sender{
[ageField resignFirstResponder];
[weightField resignFirstResponder];
}



// Implement viewDidLoad to do additional setup after loading the view, typically from a    nib.
- (void)viewDidLoad {
[super viewDidLoad];

agePickerArray = [[NSMutableArray alloc] init];
for (int age=1; age<=100; age++) {
    NSString *ageString = [NSString stringWithFormat:@"%d%",age];
                           [agePickerArray    addObject:ageString];


weightPickerArray = [[NSMutableArray alloc] init];
for (int weight = 50; weight<=500; weight++) {
    NSString *weightString = [NSString stringWithFormat:@"%d%",weight];
                            [weightPickerArray   addObject:weightString];
    }
}

Is there any other way to do what I am trying to do , because that way is not working… And if i just try and redo the implementation for each picker view i get the errors of “redefinition of…””numberOfRowsInComponent”” or which ever other property i am doing. Please help, even if I have to change it and declare the pickerViews in the .H file somehow, I don’t care what I have to do as long as I can get this to work!!

THANKS

UPDATE!!!

   @interface MainViewController : UIViewController   <FlipsideViewControllerDelegate,UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource> {

IBOutlet UITextField*ageField;

NSMutableArray *agePickerArray;
IBOutlet UITextField*weightField;
NSMutableArray *weightPickerArray;
UIPickerView *weightPickerView;
UIPickerView *agePickerView;    

   }

- (IBAction)ageFieldDidBeginEditing;
- (IBAction)weightFieldDidBeginEditing;
- (IBAction)showInfo:(id)sender;
- (IBAction)activityButtonClicked;
@end

.m file

-(IBAction)weightFieldDidBeginEditing{
//UIPickerView *weightPickerView = [[UIPickerView alloc] init];
weightField.inputView = weightPickerView;
weightPickerView.showsSelectionIndicator = YES;
weightPickerView.delegate = self;
weightPickerView.dataSource = self;
[weightPickerView release];

UIToolbar *weightToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked:)];
[weightToolBar setItems:[NSArray arrayWithObject:doneButton] animated:NO];
 weightField.inputAccessoryView = weightToolBar;
}

-(NSInteger)weightpickerView:(UIPickerView *)weightPickerView numberOfRowsInComponent:(NSInteger)component{
return [weightPickerArray count];
}

-(NSString *)weightpickerView:(UIPickerView*)weightPickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [weightPickerArray objectAtIndex:row];
}

// AGE FIELD CODE

-(IBAction)ageFieldDidBeginEditing{
//UIPickerView *agePickerView = [[UIPickerView alloc] init];
ageField.inputView = agePickerView;
agePickerView.showsSelectionIndicator = YES;
agePickerView.delegate = self;
agePickerView.dataSource = self;
[agePickerView release];

UIToolbar *ageToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked:)];
[ageToolbar setItems:[NSArray arrayWithObject:doneButton] animated:NO];
ageField.inputAccessoryView = ageToolbar; 
}

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

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
if ([pickerView isEqual: agePickerView]) {
    return [agePickerArray count];
}
if ([pickerView isEqual:weightPickerView]) {
    return [weightPickerArray count];
}
}

-(NSString *)pickerView:(UIPickerView*)agePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [agePickerArray objectAtIndex:row];

}

-(void)pickerView:(UIPickerView *)agePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    ageField.text = (NSString *) [agePickerArray objectAtIndex:row];
}

-(void)pickerDoneClicked:(id)sender{
[ageField resignFirstResponder];
[weightField resignFirstResponder];
}



// Implement viewDidLoad to do additional setup after loading the view, typically from a   nib.
- (void)viewDidLoad {
[super viewDidLoad];

agePickerArray = [[NSMutableArray alloc] init];
for (int age=1; age<=100; age++) {
    NSString *ageString = [NSString stringWithFormat:@"%d%",age];
                           [agePickerArray   addObject:ageString];


weightPickerArray = [[NSMutableArray alloc] init];
for (int weight = 50; weight<=500; weight++) {
    NSString *weightString = [NSString stringWithFormat:@"%d%",weight];
                            [weightPickerArray addObject:weightString];
    }
}
  • 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-08T14:14:48+00:00Added an answer on June 8, 2026 at 2:14 pm
    UIPickerView *weightPickerView = [[UIPickerView alloc] init];
    

    You need to declare that in your .h file (or interface).

    Are you subclassing UIPickerView?

    Edit* If you don’t want to declare those in your .h file for some reason, set a tag to your pickers.

    All of your UIPickerViews will be calling UIPickerViewDelegate methods, meaning -(NSInteger)weightpickerView:(UIPickerView *)weightPickerView numberOfRowsInComponent: (NSInteger)component will not be called unless you are subclassing and creating your own methods (which I believe you are not), i.e.

    -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent: (NSInteger)component {
      if([pickerView isEqual: agePickerView]){
       return [agePickerArray count];
      }else if([pickerView isEqual: weightPickerView]){
       return [weightPickerArray count];
      }else return 0;
    }
    

    If you’d like to do it with tags;

    weightPickerView.tag = 100; //set the tag
    
    if(pickerView.tag == 100) //check which picker it is
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with Flash Prof. CS 5.5 and have some problems using Textfields, when
Is there a way to detect if a UITextField exists using the Tag property?
I'm using Tapestry 4. I have several TextFields whose values get passed into Strings
i have been using an actionListener to pass text from numerous TextFields into a
I have a grouped table view with textfields in the tableview. For the keyboard
In my application i have a nib file (view A) containing some textFields. In
I'm using Vaadin and have a set of textfields in a form. The textfields
I have two fields that call UIPickerView (Country and Province). I'm using inputView to
Using the below code, the issue is I have two buttons and two textfields
I have ghost text in textfields that disappear when you focus on them using

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.