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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:02:40+00:00 2026-05-23T01:02:40+00:00

I want a UIPickerView to show up when I press a button (just like

  • 0

I want a UIPickerView to show up when I press a button (just like keyboard) and then go away when user taps anywhere on the screen. How can I do this? Thanks.

A bit more background: I have a UITextField called months in UITableViewCell. Now the best option for me is to put a UIPikcerView there and it will be easier for the user to just chose the month rather than having to type it out (and it’s the better way). But UIPickerView looks really ugly in a UITableViewCell, not to mention I can’t change it’s gigantic size. So what should I do in this case?

  • 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-23T01:02:41+00:00Added an answer on May 23, 2026 at 1:02 am

    This is how you should use UIPickerView for a textField in a UITableView.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle= UITableViewCellSelectionStyleNone;
        UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(110, 10, 185, 30)];
        textField.clearsOnBeginEditing = NO;
        textField.textAlignment = UITextAlignmentRight;
        textField.delegate = self;
        [cell.contentView addSubview:textField];
        //textField.returnKeyType = UIReturnKeyDone;
        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    
            // if you want a UIPickerView for first row... then do the following //
            // Here.. packSizePickerView is an object of UIPickerView
    
       if (indexPath.row == 1)
      {
        textField.tag=0;
        textField.delegate= self;
        packSizePickerView.delegate = self;
        packSizePickerView = [[UIPickerView alloc] init];
        packSizePickerView.autoresizingMask=UIViewAutoresizingFlexibleWidth;
        packSizePickerView.showsSelectionIndicator=YES;
        textField.inputView  = packSizePickerView;
        }
    
        // if you want to select date / months  in row 2, go for UIDatePickerView //
    
        if (indexPath.row == 1)
        {
            textField.tag = 1;
            UIDatePicker *datePicker = [[UIDatePicker alloc] init];
            datePicker.datePickerMode = UIDatePickerModeDate;
           [datePicker addTarget:self action:@selector(datePickerValueChangedd:) forControlEvents:UIControlEventValueChanged];
            datePicker.tag = indexPath.row;
            textField.delegate= self;
            textField.inputView = datePicker;
            [datePicker release];
    
        }
    
    }
    
    // Configure the cell...
    
    NSInteger row = [indexPath row];
    cell.textLabel.text = [myArray objectAtIndex:row];
    
    return cell;
    

    }

    And for datePickerValueChangedd

    - (void)datePickerValueChangedd:(UIDatePicker*) datePicker{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 50, 68, 68)];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateStyle = NSDateFormatterMediumStyle;
    label.text = [NSString stringWithFormat:@"%@",[df stringFromDate:datePicker.date]];
    
        NSLog(@"I am inside the datePickerValueChanged   - - %@", label.text);
    [df release];
        globalValue1 = label.text;
    
       // use a global variable to copy the value from the pickerView. //
       }    
    

    Now in the textFieldDidEndEditing:

    -(void) textFieldDidEndEditing:(UITextField *)textField {
    if (textField.tag ==0)
       [textField setText: globalValue0];
    
    if (textField.tag ==1)
       [textField setText: globalValue1];
    
    }
    

    And to resign UIDatePicker, set the UIView as a UIControl and

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

Sidebar

Related Questions

I am using a UIPickerView and I want my keyboard to never show up
want to have a Hyperlink-Button in a gridView in which I can display a
I have a UIPickerView which works correctly, now I want to add a button
How can I change the style of a UIPickerview. I want to change its
I have a UIPickerView object that has five rows that a user can select.
I want to add a UIPickerView to a UITableViewCell. Right now I am just
I want to disable the selection of certain rows in my UIPickerView . Like
I want to show a UIPickerView on becoming FirstResponder of a UITextfield not the
I want to animate my UIPickerView after pressing the button. I already have coded
I have a UIPickerView. I want a done button on top of the pickerview

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.