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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:33:36+00:00 2026-05-21T11:33:36+00:00

I try to make a UIPickerView show up when the user click on a

  • 0

I try to make a UIPickerView show up when the user click on a UITextField, I should see the DataSource and the Delegate Outlets to link them with the picker, however, it doesn’t exit when I open the nib file–> click on file owner–> inspector
the second problem is that the keyboard is not hidden when I click on the UItextField although I made a textFieldShouldReturn method which suppose to hide keyboard.

What am I missing here?

the .h file:

@interface RechercherViewController : UIViewController<UIPickerViewDataSource,UIPickerViewDelegate,UITextFieldDelegate>  {

        IBOutlet UIPickerView *pickerTypesCarburants;
        IBOutlet UIView       *pickerViewTypesCarburants;
        NSMutableArray        *typesCarburantsArray;
        IBOutlet UITextField  *typeCarburantTextField;
    }
    -(IBAction)pickerTypeCarburantsShow;
    -(IBAction)pickerTypeCarburantsDone;
    @end

the .m file :

 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView{

        return 1;

    }

    -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

        return [typesCarburantsArray count];

    }

    -(NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger) component{


        return [typesCarburantsArray objectAtIndex:row];    



    }

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

        UITouch *touch;
        touch=[touches anyObject];
        CGPoint point=[touch locationInView:self.view];
        if(CGRectContainsPoint([typeCarburantTextField frame],point))
        {
            [self pickerTypeCarburantsShow];

        }

    }
-(IBAction)pickerTypeCarburantsDone{


    NSInteger selectedRow=[pickerTypesCarburants selectedRowInComponent:0];
    NSString *item=[typesCarburantsArray objectAtIndex:selectedRow];
    typeCarburantTextField.text=[NSString stringWithFormat:@"%@",item];
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 480);
    pickerViewTypesCarburants.transform=transform;
    [UIView commitAnimations];


}

-(IBAction)pickerTypeCarburantsShow{

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 240);
    pickerViewTypesCarburants.transform=transform;
    [self.view addSubview:pickerViewTypesCarburants];
    [UIView commitAnimations];

}
-(BOOL)textFieldShouldReturn:(UITextField *)textField{

    [textField resignFirstResponder];
    return YES;

}
  • 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-05-21T11:33:37+00:00Added an answer on May 21, 2026 at 11:33 am

    First of all, you probably shouldn’t be trying to make a UIPickerView appear when you tap on a UITextField as it isn’t standard behaviour (especially if you’re suppressing the keyboard). It sounds like you need a standard UIButton that when pressed presents the UIPickerView as this would make more sense.

    Regardless, if you aren’t seeing Datasource and Delegate outlets in IB, try applying them manually in your code.

    pickerTypesCarburants.delegate = self;
    pickerTypesCarburants.dataSource = self;
    

    To answer your second question, the keyboard will only hide when you press the return key with the textFieldShouldReturn method you have implemented. The UITextField will also have to have its delegate set (I’m assuming you’re doing this in IB as not listed in your .m file). To make the keyboard hide as soon as you press the UITextField, you would to alter your pickerTypeCarburantsShow method:

    -(IBAction)pickerTypeCarburantsShow{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    CGAffineTransform transform=CGAffineTransformMakeTranslation(0, 240);
    pickerViewTypesCarburants.transform=transform;
    [self.view addSubview:pickerViewTypesCarburants];
    [UIView commitAnimations];
    [typeCarburantTextField resignFirstResponder];
    }
    

    This will make sure that the keyboard is hidden immediately (rather than on pressing the return button). Again, I’d question why you would want to make a UIPickerView appear when tapping a UITextField as it probably goes against the Human Interface Guidelines.

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

Sidebar

Related Questions

I try to make a common solution for the following task: onclick event listener
I try to make a query to my database with LINQ to SQL. example
When I try to make a new instance of the Auth-module object (Auth::factory()), Kohana
Im getting this error when I try and make an object. Here is my
I'm encountering a FileNotFoundException when I try to make a file using RandomAccessFile: RandomAccessFile
I'm using CMake and I want to try and make it so I have
I am having issues with properties file when I try to make my standalone
Been a tough week, will try to make this as clear as possible. Appreciate
When I create a form, I try to make accessibility a top priority, but
I am about to start a pilot project in our company to introduce agile

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.