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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:34:03+00:00 2026-05-30T11:34:03+00:00

Ok so I’ve gone through pretty much all the SO articles on this subject

  • 0

Ok so I’ve gone through pretty much all the SO articles on this subject and can’t resolve my particular situation. I have a view controller with 3 text fields and a text area. One of the text fields is for a date. When the user enters this field, I want to hide the keyboard and show the date picker.

The issue I run into with my code so far is that the keyboard shows up when I enter any of the fields, but then does not disappear no matter what I’ve tried.

I could not find any sample app that has this feature and would like some direction on how to resolve this issue.

UPDATE: I fixed the first part of this and now can hide my keyboard when I get to the date field.

Here is what it looks like when I click on the date field

This was using the below code:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

{

if ( textField.tag == 1 )
{

    [self.view endEditing:TRUE];

    [lblDesc2 resignFirstResponder];
    [lblTitle resignFirstResponder];
    [lblExcerpt resignFirstResponder];

    NSLog(@"The method was called for textField ");

    [self showDatePicker];
    return NO;
}
else
{
    return YES;
}

}

Now what I need to do is pull up the date picker and here is my code for that which is not working yet:

- (void) showDatePicker{

CGRect pickerFrame = CGRectMake(0,250,325,0);

datePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
[datePicker addTarget:self action:@selector(pickerChanged:)               forControlEvents:UIControlEventValueChanged];

[scrollView addSubview:datePicker];

NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateStyle = NSDateFormatterMediumStyle;

datePicker.datePickerMode = UIDatePickerModeDate;

[datePicker release]; 


}

.h

    #import <UIKit/UIKit.h>
    #import "QuoteViewController.h"
    #import "SubjectViewController.h"
    #import "CategoryViewController.h"

    @class Quote, SubjectViewController, QuoteViewController;

    @interface AddQuoteViewController : UIViewController <UITextFieldDelegate>{

    @private
        UIDatePicker *datePicker;
        UIBarButtonItem *doneButton;    // this button appears only when the date picker is open
        NSArray *dataArray;
        NSDateFormatter *dateFormatter;

        IBOutlet UITextField *lblTitle;
        IBOutlet UITextField *lblDesc2;
        IBOutlet UITextField *lblDate;
        IBOutlet UITextView *lblExcerpt;
        IBOutlet UITextField *lblNote;
        QuoteViewController *qvc;
        SubjectViewController *svc;
        //UITextField *editingField;
        IBOutlet UIScrollView *scrollView;

    }


    @property (nonatomic, retain) UIScrollView *scrollView;
    @property (nonatomic, retain) IBOutlet UIDatePicker *datePicker; 
    @property (nonatomic, retain) IBOutlet UIBarButtonItem *doneButton;

    @property (nonatomic, retain) NSArray *dataArray; 
    @property (nonatomic, retain) NSDateFormatter *dateFormatter; 

    //- (IBAction)doneAction:(id)sender;    // when the done button is clicked
    //- (IBAction)dateAction:(id)sender;    // when the user has changed the date picke values (m/d/y)

    @property (nonatomic,assign) QuoteViewController *qvc;
    @property (nonatomic,assign) SubjectViewController *svc;

    @end

.m

    #import "AddQuoteViewController.h"
    #import "Category.h"
    #import "QuotesAppDelegate.h"
    #import "Quote.h"
    #import "QuoteMap.h"


    @implementation AddQuoteViewController

    @synthesize svc, qvc;
    @synthesize datePicker, doneButton, dataArray, dateFormatter, scrollView;


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

        self.title = @"Add Quote";

        self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] 
                                                  initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
                                                   target:self action:@selector(cancel_Clicked:)] autorelease];

        self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] 
                                                   initWithBarButtonSystemItem:UIBarButtonSystemItemSave 
                                                   target:self action:@selector(save_Clicked:)] autorelease];

        self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

        self.dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
        [self.dateFormatter setDateStyle:NSDateFormatterShortStyle];
        [self.dateFormatter setTimeStyle:NSDateFormatterNoStyle];

        CGRect pickerFrame = CGRectMake(0,250,325,0);

        datePicker = [[UIDatePicker alloc] initWithFrame:pickerFrame];
        [datePicker addTarget:self action:@selector(pickerChanged:)               forControlEvents:UIControlEventValueChanged];

        [scrollView addSubview:datePicker];

        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        df.dateStyle = NSDateFormatterMediumStyle;

        datePicker.datePickerMode = UIDatePickerModeDate;

        lblDate.tag = 1;

        [datePicker release]; 

     }


    - (void) viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];

        //Set the textboxes to empty string.

        //Display the selected quote.
        lblExcerpt.text = @"";
        lblTitle.text = @"";
        lblDesc2.text = @"";
        lblDate.text = @"";

        NSLog(@"AddQuoteViewController initialized...");

        //Make the Category name textfield to be the first responder.
    //  [lblTitle becomeFirstResponder];
    }


    - (void)pickerChanged:(id)sender
    {

        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        df.dateStyle = NSDateFormatterMediumStyle;
        lblDate.text = [NSString stringWithFormat:@"%@",
                          [df stringFromDate:datePicker.date]];

        NSLog(@"value: %@",[sender date]);
    }


- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{

if ( textField.tag == 1 )
{

    [self.view endEditing:TRUE];

    [lblDesc2 resignFirstResponder];
    [lblTitle resignFirstResponder];
    [lblExcerpt resignFirstResponder];

    NSLog(@"The method was called for textField ");

    [self showDatePicker];
    return NO;
}
else
{
    return YES;
}
}
    - (void)viewDidUnload
    {
        self.dataArray = nil;
        self.dateFormatter = nil;
    }



    - (void)dealloc {
        [lblTitle release];
        [lblDesc2 release];
        [lblDate release];
        [lblExcerpt release];
        [doneButton release];
        [dataArray release];
        [scrollView release];
        [datePicker release];
        [dateFormatter release];
        [super dealloc];
    }

    @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-05-30T11:34:04+00:00Added an answer on May 30, 2026 at 11:34 am
    -(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    
     //do what you want to do when user is touching the textfield. e.g. Display the DatePicker 
    
           return NO;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.