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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:59:27+00:00 2026-05-25T05:59:27+00:00

I am trying to load back the date which the user last selected every

  • 0

I am trying to load back the date which the user last selected every time my view appears.

This IBAction is invoked when my datePicker changes value. datepick is my datePicker

I am doing this to save to it’s rootVC property.

- (void)viewWillDisappear:(BOOL)animated {
    BookingViewController *bookingVC = [[BookingViewController alloc] init];
    bookingVC.selectedDate = [datepick date];
    [bookingVC release];
}

Load it everytime the viewAppears.

- (void)viewWillAppear:(BOOL)animated
{       
    // set datePicker Range.
    NSDate *todaysDate = [NSDate date];
    NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
    [dateComponents setHour:48];
    NSDateComponents *dateComponents2 = [[NSDateComponents alloc] init];
    [dateComponents2 setMinute:30];
    NSDate *maxDate = [gregorian dateByAddingComponents:dateComponents toDate:todaysDate  options:0];
    NSDate *minDate = [gregorian dateByAddingComponents:dateComponents2 toDate:todaysDate  options:0];
    datepick.maximumDate = maxDate;
    datepick.minimumDate = minDate;
    if (self.dateToSet == nil) {
        [datepick setDate:minDate animated:YES];
    }
    else {
        [datepick setDate:dateToSet animated:YES];
    }
    [dateComponents release];
    [dateComponents2 release];
    [gregorian release];
    choice = [datepick date];   
    choiceString = [dateFormatter stringFromDate:choice];
    dateTextfield.text = choiceString;

}

Before pushing dateViewController I pass the saved date(self.selectedDate) to the dateViewController.dateToSet property

- (void)advanceBooking:(id) sender {
    DateViewController *dateViewController= [[DateViewController alloc]
                                           initWithNibName:@"DateViewController" 
                                           bundle:nil];
    if (self.selectedDate == nil) {
        selectedDate = [[NSDate alloc] init];
    }
    dateViewController.dateToSet = self.selectedDate;
    NSLog(@"dateVC.dateToSet :%@ selectedDate:%@", dateViewController.dateToSet, self.selectedDate); // both read as current date though it was the first call? weird.
    dateViewController.hidesBottomBarWhenPushed = YES;
    dateViewController.navigationItem.hidesBackButton = YES;
    [self.navigationController pushViewController:dateViewController animated:YES];
    [dateViewController release];

}

I guess it has got something with how I init the property? When Should I init them?

  • 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-25T05:59:27+00:00Added an answer on May 25, 2026 at 5:59 am

    Since I am passing back up the hierarchy, I should not create a new object of the class.

    So instead, I should get back the object that was already created as such,

    At DateViewController.m (child view)

    NSArray *viewControllers = [self.navigationController viewControllers];
    BookingViewController *bookingVC = (BookingViewController *)[viewControllers objectAtIndex:viewControllers.count - 2];
    [bookingVC setSelectedDate:[datepick date]];
    

    At BookingViewController.m (parent view)

    if (self.selectedDate != nil) {
        dateViewController.dateToSet = self.selectedDate;
    }
    

    Then set it everytime during viewDidLoad at DateViewController.m

    if (self.dateToSet == nil) {
        [datepick setDate:minDate animated:YES];
    }
    else {
        [datepick setDate:dateToSet animated:YES];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement back button on this full ajax website.. I tried jquery
I am trying to save data in JSON and load it back into the
Coming back to flex after not using it for a while, trying to load
I am trying to load an XML file into a tree view control, edit
I am trying to load an edit form which is a PartialView, into a
I'm trying to load JSON back into an object. The loads method seems to
A bit of back story: I am currently trying to load a texture with
I'm trying to read binary data to load structs back into memory so I
I have a problem with out of memory when I'm trying load a few
Trying to load a shared lib out of the current '.' dir in a

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.