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

  • Home
  • SEARCH
  • 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 9320045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:32:07+00:00 2026-06-19T03:32:07+00:00

I’m having trouble saving to one variable letsMeet.startTimeLabel. Right after selecting NSLog shows the

  • 0

I’m having trouble saving to one variable letsMeet.startTimeLabel. Right after selecting NSLog shows the correct Value, however, after I save to another variable (letsMeet.endTimeLabel), letsMeet.startTimeLabel changes to (NULL). Below is the code:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
letsMeet = (LetsMeet *) [NSEntityDescription insertNewObjectForEntityForName:@"LetsMeet" inManagedObjectContext:managedObjectContext];
switch (actionSheet.tag)
{
    case 1:
    {
        if (buttonIndex == 0)
        {
            UIDatePicker *startDatePicker = (UIDatePicker *)[actionSheet viewWithTag:kDatePickerTag1];

            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
            [dateFormatter setDateFormat:@"dd"];
            NSDate *selectedDate = [startDatePicker date];

            NSDateFormatter *dayFormatter = [[NSDateFormatter alloc] init];
            [dayFormatter setDateFormat:@"EEEE"];
            NSDate *selectedDay= [startDatePicker date];

            NSDateFormatter *monthFormatter = [[NSDateFormatter alloc] init];
            [monthFormatter setDateFormat:@"MMMM"];
            NSDate *selectedMonth = [startDatePicker date];

            NSString *date = [[NSString alloc] initWithFormat:@"%@", [dateFormatter stringFromDate:selectedDate]];
            DateLabel.text = date;
            [letsMeet setDateLabel:date];

            NSString *month = [[NSString alloc] initWithFormat:@"%@", [dayFormatter stringFromDate:selectedMonth]];
            MonthLabel.text = month;
            [letsMeet setMonthLabel:month];

            NSString *day = [[NSString alloc] initWithFormat:@"%@", [monthFormatter stringFromDate:selectedDay]];
            DayLabel.text = day;
            [letsMeet setDateLabel:day];

            NSDateFormatter *timeFormatter = [[NSDateFormatter alloc] init];
            [timeFormatter setDateFormat: @"h:mm a"];
            NSDate *selectedStartTime = [startDatePicker date];

            NSString *startTime = [[NSString alloc] initWithFormat:@"%@", [timeFormatter stringFromDate:selectedStartTime]];
            StartTimeLabel.text = startTime;
            [letsMeet setStartTimeLabel:startTime];

            NSError *error = nil;
            if (![managedObjectContext save:&error]){

                NSLog(@"Error Saving");
            }
        }
        NSLog (@"This is the StartTime after selecting %@", letsMeet.startTimeLabel);
    }
    break;

    case 2:
    {
        if (buttonIndex == 0)
        {
            UIDatePicker *endTimePicker = (UIDatePicker *)[actionSheet viewWithTag:kDatePickerTag2];
            NSDateFormatter *endTimeFormatter = [[NSDateFormatter alloc] init];
            [endTimeFormatter setDateFormat: @"h:mm a"];
            NSDate *endSelectedTime = [endTimePicker date];
            NSString *endTime = [[NSString alloc] initWithFormat:@"%@", [endTimeFormatter stringFromDate:endSelectedTime]];
            EndTimeLabel.text = endTime;
            [letsMeet setEndTimeLabel:endTime];
            NSLog (@"This is the EndTime %@", letsMeet.endTimeLabel);
            NSLog (@"This is the StartTime after selecting BOTH %@", letsMeet.startTimeLabel);
        }
        else if (buttonIndex == 1)
        {
            EndTimeLabel.text = @"Whenever";
            [letsMeet setEndTimeLabel:EndTimeLabel.text];
        }
        NSError *error = nil;
        if (![managedObjectContext save:&error]) {
    }

}break;

    // Handle the error.
}

}


-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    UIViewController *destinationViewController = segue.destinationViewController;
    NSLog (@"Prepare For Segue StartTime %@", letsMeet.startTimeLabel);
    NSLog (@"Prepare For Segue EndTime%@", letsMeet.endTimeLabel);
}

Here is the log:

2013-02-20 21:38:24.253 AppointmentTime[3129:c07] This is the StartTime after selecting 9:30 AM
2013-02-20 21:38:32.325 AppointmentTime[3129:c07] This is the EndTime 12:15 PM
2013-02-20 21:38:32.325 AppointmentTime[3129:c07] This is the StartTime after Selecting BOTH (null)
2013-02-20 21:38:34.069 AppointmentTime[3129:c07] Prepare For Segue StartTime (null)
2013-02-20 21:38:34.069 AppointmentTime[3129:c07] Prepare For Segue EndTime12:15 PM

Q: Why would letsMeet.startTimeLabel show up correct the first time and after selecting EndTime, it changes to NULL. Please note EndTime continues to show the correct Value all the way up to prepareForSegue. Weird!

  • 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-19T03:32:08+00:00Added an answer on June 19, 2026 at 3:32 am

    According to your logs and code , you are entering the switch block twice. Which means you are entering the actionSheet:clickedButtonAtIndex: method twice. So each time you enter the method

    letsMeet = (LetsMeet *) [NSEntityDescription insertNewObjectForEntityForName:@"LetsMeet" inManagedObjectContext:managedObjectContext];
    

    statement is executed twice, in turn creating two objects. You can see this by doing a fetch from the store.

    So you are checking for properties in two different objects and hence the null.

    If you are using just one managed object, you can probably add a check for nil for the object before executing insertNewObjectForEntityForName:inManagedObjectContext:. This will make sure you are using the same object.

    If you are using more than one object at the same time use the object id or some unique key to identify your object and manipulate it.

    Edit:
    You can check for nil with the following code:

    if(letsMeet==Nil){
        letsMeet = (LetsMeet *) [NSEntityDescription insertNewObjectForEntityForName:@"LetsMeet" inManagedObjectContext:managedObjectContext];
    }
    

    This will work only, if the object you are calling the actionSheet:clickedButtonAtIndex: method is always in memory. But since you are persisting you might want to fetch the object from the store and then check for no. of objects.

    NSError *error;
    NSFetchRequest *request = [[NSFetchRequest alloc] init];
    [request setEntity:[NSEntityDescription entityForName:@"LetsMeet" inManagedObjectContext:managedObjectContext]];
    NSArray *objectArray = [managedObjectContext executeFetchRequest:request error:&error]
    if(objectArray.count==0){
        letsMeet = (LetsMeet *) [NSEntityDescription insertNewObjectForEntityForName:@"LetsMeet" inManagedObjectContext:managedObjectContext];
    }else{
        letsMeet = (LetsMeet *)[objectArray objectAtIndex:0];
    }
    

    Note: If you need to persist only a couple of variables, core-data might be an overkill. Use NSUserDefaults instead and keep it simple.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.