我能够在 uipopover 中弹出一个 uidatepicker 并将数据发送回弹出它的 VC。我基本上有两个这样的 VC(StartdateVC 和 endDateVC),它们会弹出 uidatepicker。我必须保存最后一个日期并在重新启动时使用它启动 uidatepicker。所以我的代码在 popover 的 viewDidLoad 中,
if (myLastDate == nil) {
[self.mydatePicker setDate:[NSDate date] animated:NO];
} else {
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateStyle : NSDateFormatterLongStyle];
[self.mydatePicker setDate:[formatter dateFromString:myLastDate] animated:NO];
[super viewDidLoad];
}
我在 NSUserDefaults 中保存了 myLastDate 并在此处检索它。我希望能够区分哪个 VC 启动了弹出窗口,因此能够启动具有相应最后日期的 uidatepicker。非常感谢任何想法或提示。:)
编辑:在每个 VC 中,我都有这个方法:
- (IBAction)calendarbutton:(UIButton *)sender {
UIView *anchor = sender;
selectDatePopover *selectDatePopoverinstance =
[self.storyboard instantiateViewControllerWithIdentifier:@"selectDatePopover"];
// selectDatePopover.delegate = self;
_popover = [[UIPopoverController alloc] initWithContentViewController:selectDatePopoverinstance];
[_popover presentPopoverFromRect:anchor.frame inView:anchor.superview permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
selectDatePopoverinstance.delegate = self;
_popover.delegate =self;
}