UIDatePicker EventValueChanged not showing actual Date/Time












0















I have two UILabels



1: Time (Format: HH:MM)



2: Date (Format: MMMM dd, yyyy)



I have a UIDatePicker which is the UIDatePickerModeDateAndTime called: timeObjectReportedDatePicker



Each time the value of the datePicker changes, the two labels are supposed to show the respective value from the datePicker. So label 1 will show the HH:MM and label 2 will show the MMMM, dd, yyyy.



However this is not the case; rather for testing purposes I'm logging the value of the datePicker; which is only grabbing the current time/date. Regardless of the date that I change, or time; the value only changes to the actual date and time and not the picker value. Here is the code that I have in the header.



@property (nonatomic, strong) IBOutlet UIDatePicker *timeObjectReportedDatePicker;

- (IBAction)datePickerValueChanged:(id)sender;


Here is the code for the datePickerValueChanged method



-(void)datePickerValueChanged:(id)sender{

NSLog(@"datePicker Value Changed");
NSDate *today1 = self.timeObjectReportedDatePicker.date;

NSLog(@"PickerValue: %@",today1);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
NSString *dateString11 = [dateFormat stringFromDate:today1];
dateObjectReportedUILabel.text=dateString11;
}


I do have the UIDatePicker SentEvent ValueChanged connected as an IBOutlet to the header file for the valueDidChange event.



Could someone shed some light as to what I'm doing wrong here?










share|improve this question























  • You did not link timeObjectReportedDatePicker to the outlet.

    – E.Coms
    Nov 21 '18 at 3:55
















0















I have two UILabels



1: Time (Format: HH:MM)



2: Date (Format: MMMM dd, yyyy)



I have a UIDatePicker which is the UIDatePickerModeDateAndTime called: timeObjectReportedDatePicker



Each time the value of the datePicker changes, the two labels are supposed to show the respective value from the datePicker. So label 1 will show the HH:MM and label 2 will show the MMMM, dd, yyyy.



However this is not the case; rather for testing purposes I'm logging the value of the datePicker; which is only grabbing the current time/date. Regardless of the date that I change, or time; the value only changes to the actual date and time and not the picker value. Here is the code that I have in the header.



@property (nonatomic, strong) IBOutlet UIDatePicker *timeObjectReportedDatePicker;

- (IBAction)datePickerValueChanged:(id)sender;


Here is the code for the datePickerValueChanged method



-(void)datePickerValueChanged:(id)sender{

NSLog(@"datePicker Value Changed");
NSDate *today1 = self.timeObjectReportedDatePicker.date;

NSLog(@"PickerValue: %@",today1);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
NSString *dateString11 = [dateFormat stringFromDate:today1];
dateObjectReportedUILabel.text=dateString11;
}


I do have the UIDatePicker SentEvent ValueChanged connected as an IBOutlet to the header file for the valueDidChange event.



Could someone shed some light as to what I'm doing wrong here?










share|improve this question























  • You did not link timeObjectReportedDatePicker to the outlet.

    – E.Coms
    Nov 21 '18 at 3:55














0












0








0








I have two UILabels



1: Time (Format: HH:MM)



2: Date (Format: MMMM dd, yyyy)



I have a UIDatePicker which is the UIDatePickerModeDateAndTime called: timeObjectReportedDatePicker



Each time the value of the datePicker changes, the two labels are supposed to show the respective value from the datePicker. So label 1 will show the HH:MM and label 2 will show the MMMM, dd, yyyy.



However this is not the case; rather for testing purposes I'm logging the value of the datePicker; which is only grabbing the current time/date. Regardless of the date that I change, or time; the value only changes to the actual date and time and not the picker value. Here is the code that I have in the header.



@property (nonatomic, strong) IBOutlet UIDatePicker *timeObjectReportedDatePicker;

- (IBAction)datePickerValueChanged:(id)sender;


Here is the code for the datePickerValueChanged method



-(void)datePickerValueChanged:(id)sender{

NSLog(@"datePicker Value Changed");
NSDate *today1 = self.timeObjectReportedDatePicker.date;

NSLog(@"PickerValue: %@",today1);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
NSString *dateString11 = [dateFormat stringFromDate:today1];
dateObjectReportedUILabel.text=dateString11;
}


I do have the UIDatePicker SentEvent ValueChanged connected as an IBOutlet to the header file for the valueDidChange event.



Could someone shed some light as to what I'm doing wrong here?










share|improve this question














I have two UILabels



1: Time (Format: HH:MM)



2: Date (Format: MMMM dd, yyyy)



I have a UIDatePicker which is the UIDatePickerModeDateAndTime called: timeObjectReportedDatePicker



Each time the value of the datePicker changes, the two labels are supposed to show the respective value from the datePicker. So label 1 will show the HH:MM and label 2 will show the MMMM, dd, yyyy.



However this is not the case; rather for testing purposes I'm logging the value of the datePicker; which is only grabbing the current time/date. Regardless of the date that I change, or time; the value only changes to the actual date and time and not the picker value. Here is the code that I have in the header.



@property (nonatomic, strong) IBOutlet UIDatePicker *timeObjectReportedDatePicker;

- (IBAction)datePickerValueChanged:(id)sender;


Here is the code for the datePickerValueChanged method



-(void)datePickerValueChanged:(id)sender{

NSLog(@"datePicker Value Changed");
NSDate *today1 = self.timeObjectReportedDatePicker.date;

NSLog(@"PickerValue: %@",today1);
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
NSString *dateString11 = [dateFormat stringFromDate:today1];
dateObjectReportedUILabel.text=dateString11;
}


I do have the UIDatePicker SentEvent ValueChanged connected as an IBOutlet to the header file for the valueDidChange event.



Could someone shed some light as to what I'm doing wrong here?







ios objective-c uidatepicker






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 '18 at 3:23









Nathan DenlingerNathan Denlinger

6917




6917













  • You did not link timeObjectReportedDatePicker to the outlet.

    – E.Coms
    Nov 21 '18 at 3:55



















  • You did not link timeObjectReportedDatePicker to the outlet.

    – E.Coms
    Nov 21 '18 at 3:55

















You did not link timeObjectReportedDatePicker to the outlet.

– E.Coms
Nov 21 '18 at 3:55





You did not link timeObjectReportedDatePicker to the outlet.

– E.Coms
Nov 21 '18 at 3:55












1 Answer
1






active

oldest

votes


















1














change your action method as like



    - (IBAction)datePickerValueChanged:(UIDatePicker *)sender;


and execute the method as like



     -(void)datePickerValueChanged:(UIDatePicker*)sender{
[self updateReportlabel: sender];

}

// for change the year and month
-(void)updateReportlabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
dateObjectReportedUILabel.text = [dateFormat stringFromDate:sender.date];
// call the update time method
[self updateTimelabel: sender];

}
// for change the time
-(void)updateTimelabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm"];
yourFirstLabel.text = [dateFormat stringFromDate:sender.date];

}





share|improve this answer


























  • Thank you! That works perfectly! That makes sense. I appreciate it.

    – Nathan Denlinger
    Nov 21 '18 at 3:49











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404822%2fuidatepicker-eventvaluechanged-not-showing-actual-date-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














change your action method as like



    - (IBAction)datePickerValueChanged:(UIDatePicker *)sender;


and execute the method as like



     -(void)datePickerValueChanged:(UIDatePicker*)sender{
[self updateReportlabel: sender];

}

// for change the year and month
-(void)updateReportlabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
dateObjectReportedUILabel.text = [dateFormat stringFromDate:sender.date];
// call the update time method
[self updateTimelabel: sender];

}
// for change the time
-(void)updateTimelabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm"];
yourFirstLabel.text = [dateFormat stringFromDate:sender.date];

}





share|improve this answer


























  • Thank you! That works perfectly! That makes sense. I appreciate it.

    – Nathan Denlinger
    Nov 21 '18 at 3:49
















1














change your action method as like



    - (IBAction)datePickerValueChanged:(UIDatePicker *)sender;


and execute the method as like



     -(void)datePickerValueChanged:(UIDatePicker*)sender{
[self updateReportlabel: sender];

}

// for change the year and month
-(void)updateReportlabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
dateObjectReportedUILabel.text = [dateFormat stringFromDate:sender.date];
// call the update time method
[self updateTimelabel: sender];

}
// for change the time
-(void)updateTimelabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm"];
yourFirstLabel.text = [dateFormat stringFromDate:sender.date];

}





share|improve this answer


























  • Thank you! That works perfectly! That makes sense. I appreciate it.

    – Nathan Denlinger
    Nov 21 '18 at 3:49














1












1








1







change your action method as like



    - (IBAction)datePickerValueChanged:(UIDatePicker *)sender;


and execute the method as like



     -(void)datePickerValueChanged:(UIDatePicker*)sender{
[self updateReportlabel: sender];

}

// for change the year and month
-(void)updateReportlabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
dateObjectReportedUILabel.text = [dateFormat stringFromDate:sender.date];
// call the update time method
[self updateTimelabel: sender];

}
// for change the time
-(void)updateTimelabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm"];
yourFirstLabel.text = [dateFormat stringFromDate:sender.date];

}





share|improve this answer















change your action method as like



    - (IBAction)datePickerValueChanged:(UIDatePicker *)sender;


and execute the method as like



     -(void)datePickerValueChanged:(UIDatePicker*)sender{
[self updateReportlabel: sender];

}

// for change the year and month
-(void)updateReportlabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM dd, yyyy"];
dateObjectReportedUILabel.text = [dateFormat stringFromDate:sender.date];
// call the update time method
[self updateTimelabel: sender];

}
// for change the time
-(void)updateTimelabel:(UIDatePicker*)sender{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"HH:mm"];
yourFirstLabel.text = [dateFormat stringFromDate:sender.date];

}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 3:45

























answered Nov 21 '18 at 3:39









Anbu.KarthikAnbu.Karthik

62.4k17122112




62.4k17122112













  • Thank you! That works perfectly! That makes sense. I appreciate it.

    – Nathan Denlinger
    Nov 21 '18 at 3:49



















  • Thank you! That works perfectly! That makes sense. I appreciate it.

    – Nathan Denlinger
    Nov 21 '18 at 3:49

















Thank you! That works perfectly! That makes sense. I appreciate it.

– Nathan Denlinger
Nov 21 '18 at 3:49





Thank you! That works perfectly! That makes sense. I appreciate it.

– Nathan Denlinger
Nov 21 '18 at 3:49




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404822%2fuidatepicker-eventvaluechanged-not-showing-actual-date-time%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()