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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:47:06+00:00 2026-06-16T23:47:06+00:00

I have a Button in my view .On tapping the Button you get a

  • 0

I have a Button in my view.On tapping the Button you get a datepicker which defaults to today’s date, the user can then select the date they want to search for events.
The problem is, no matter what date I select, it always returns the current day and adds this to my TextField which i have placed inside mu Button.Can any one tell me where I am wrong.am setting the date picker programatically.

Below is my code hopefully someone can help me out!

//displaying date picker while clicking on button

 - (IBAction)startDateButtonAction:(id)sender
  {
     if ([popOverController isPopoverVisible]) {
    [popOverController dismissPopoverAnimated:YES];
  }
    UIViewController* popoverContent = [[UIViewController alloc] init]; //ViewController
    UIView *popoverView1 = [[UIView alloc] init];   //view
    datePicker          =[[UIDatePicker alloc]init];//Date picker
    datePicker.frame    =CGRectMake(0,0,240, 150);
    datePicker.datePickerMode = UIDatePickerModeDate;
    [datePicker setMaximumDate:[[NSDate date] dateByAddingTimeInterval:24*60*60*-6]];
    [datePicker setMinimumDate:[DateFormatter getSubtractedDateForomCurrentDateWith:35]];
    datePicker.date     = [DateFormatter getDateFromString:startDateLabel.text];
    datePicker.selected = YES;
    [datePicker addTarget:self action:@selector(datePickerValue)       forControlEvents:UIControlEventValueChanged];
    [popoverView1 addSubview:datePicker];
    popoverContent.view = popoverView1;
    popOverController = [[UIPopoverController alloc]    initWithContentViewController:popoverContent];
    [popOverController setPopoverContentSize:CGSizeMake(240, 150) animated:NO];
    [popOverController presentPopoverFromRect:startDateButton.frame inView:headerView   permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

//action function while selecting any of the date from date picker

 - (void) datePickerValue
  {
     NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];
     [offsetComponents setDay:-6]; 
     NSDate *labelStartDate = datePicker.date;
     startDate = [DateFormatter getOnlyDateComponentsFromDate:labelStartDate];
     NSDate *labelEndDate = [self addDayToDate:startDate Number:6];
     startDateLabel.text = [DateFormatter getDateStringddmmyyy:labelStartDate];
     endDateLabel.text   = [DateFormatter getDateStringddmmyyy:labelEndDate];
   }

[including the functions that am used here]

//used for getting date components
+(NSDate *) getOnlyDateComponentsFromDate:(NSDate *)date
{
unsigned int flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components = [calendar components:flags fromDate:date];
NSDate* dateOnly = [calendar dateFromComponents:components];
return dateOnly;
}  


 - (NSDate *) addDayToDate:(NSDate *)date Number:(int) number
{
  NSDate *newDate = [date dateByAddingTimeInterval:60*60*24*number];
  return newDate;
}

Iam using ARC.
here datePicker.date gives me only the current date even though I select any other dates

  • 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-16T23:47:07+00:00Added an answer on June 16, 2026 at 11:47 pm

    I found out my mistake at last..The problem was with my code where i set the maximum and minimum value for the datePicker.removing the code for setting maximum and minimum value the code works fine..

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

Sidebar

Related Questions

I have a button in a view which refuses to work. I've got in
I have a view with which I have a button calling the following method.
i have view controller which contains a button which show the image library ,if
I am using a list view in which i have button for downloading. I
I have a button created in my view. In the ViewModel, I wish to
We have place a button on a view. When we press it, nothing happens.
I am new to iphone development. I have created a button in the view.
I have a an object view with data and a button on that view.
I have a view containing a button. And i want to perform an action
I have a view with a button at the bottom of the portrait screen,

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.