下面的函數(即dateChanged())由UIDatePickersolve觸發。我的問題是,如何從NSDate檢索字符串?
NSLog(@"Future: %@", futureDate);
返回'null'。但是,
NSLog(@"Today: %@", today);
工作得很好。
我知道,鑄造發件人爲的UIDatePicker,讓我解決使用問題:
futureDate = [dateFormat stringFromDate:sender.date];
,但我不明白爲什麼我不能投發件人爲一個NSDate。任何有識之士將不勝感激。
//- (IBAction)dateChanged:(UIDatePicker*)sender {
- (IBAction)dateChanged:(NSDate *)sender {
NSDate* todaysDate = [NSDate date];
NSDateFormatter* dateFormat;
dateFormat=[[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MMMM d, yyyy hh:mm:ssa"];
NSString * today;
NSString * futureDate;
today=[dateFormat stringFromDate:todaysDate];
NSLog(@"Today: %@", today);
futureDate = [dateFormat stringFromDate:sender];
NSLog(@"Future: %@", futureDate);
}