i am using a uidatepicker inside a uipopover in many viewcontrollers. I need to keep the picked date in each of these viewcontrollers different so I can load them back when uidatepicker is launched again in their respective VC's. How do I accomplish this?
how to send data from uiViewController to uipopover so that the datepicker is set to corresponding VC's intial date. Help much appreciated.
VC code which launches uipopover designed in storyboard:
- (IBAction)calendarbutton:(UIButton *)sender {
UIView *anchor = sender;
selectDatePopover *selectDatePopoverinstance =
[self.storyboard instantiateViewControllerWithIdentifier:@"selectDatePopover"];
_popover = [[UIPopoverController alloc]
initWithContentViewController:selectDatePopoverinstance];
[_popover presentPopoverFromRect:anchor.frame
inView:anchor.superview
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
selectDatePopoverinstance.delegate = self;
_popover.delegate =self;
}
code in uipopover:
- (void)viewDidLoad
{
NSLog(@"viewdidload");
NSUserDefaults *datepicks = [NSUserDefaults standardUserDefaults];
NSString *myLastDate = [datepicks objectForKey:@"myLastDate"];
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];
NSLog(@"insideview");
// Do any additional setup after loading the view.
}