我目前有一个DatePickerViewController
我在情节提要中创建的具有 UIDatePicker 的弹出框。我希望能够关闭弹出窗口并将日期发送到我的原始视图ViewController
,但我不确定如何执行此操作。我知道如何从 UIDatePicker 获取日期,只是不知道如何在弹出框被解除时获取该数据。
我正在尝试这个,ViewController
但从未显示 NSLog 输出......
- (void) popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
NSDate *selectedDate = ((DatePickerViewController *) popoverController.contentViewController).datePicker.date;
NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [calendar components:(NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit) fromDate:selectedDate];
int selectedYear = [dateComponents year];
int selectedMonth = [dateComponents month];
int selectedDay = [dateComponents day];
self.dateLabel.text = [NSString stringWithFormat:@"%d/%d/%d",selectedMonth,selectedDay,selectedYear];
NSLog(@"hello world"); // never shows up
}