// // MonthPickerViewController.m // RedAnt ERP Mobile // // Created by Ray on 8/18/15. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved. // #import "MonthPickerViewController.h" @interface MonthPickerViewController () @end @implementation MonthPickerViewController - (NSString*)formatDate:(NSDate *)date { // A convenience method that formats the date in Month-Year format NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @"MM/yyyy"; return [formatter stringFromDate:date]; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // I will be using the delegate here self.monthPicker.monthPickerDelegate = self; // Set the label to show the date // Some options to play around with self.monthPicker.maximumYear = 2050; self.monthPicker.minimumYear = 2016; self.monthPicker.yearFirst = YES; // // NSDateComponents* dateParts = [[NSDateComponents alloc] init]; // // dateParts.month = 10; // dateParts.year = 2009; self.monthPicker.date = self.current_date; // self.label.text = [NSString stringWithFormat:@"Selected: %@", [self formatDate:self.monthPicker.date]]; self.label.text = [NSString stringWithFormat:@"Selected: %@", [self formatDate:self.monthPicker.date]]; } - (IBAction)onSetValue:(id)sender { // if(self.dirty == false) // return; if (self.delegate && [self.delegate respondsToSelector:@selector(MPValueChanged:indexPath:)]) { [self.delegate MPValueChanged: [self formatDate:self.monthPicker.date] indexPath:self.updatePosition]; } [self.navigationController popViewControllerAnimated:false]; // if(self.returnValue) // self.returnValue(self.cadedate); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)monthPickerWillChangeDate:(SRMonthPicker *)monthPicker { // Show the date is changing (with a 1 second wait mimicked) self.label.text = [NSString stringWithFormat:@"Was: %@", [self formatDate:monthPicker.date]]; } - (void)monthPickerDidChangeDate:(SRMonthPicker *)monthPicker { // All this GCD stuff is here so that the label change on -[self monthPickerWillChangeDate] will be visible dispatch_queue_t delayQueue = dispatch_queue_create("com.simonrice.SRMonthPickerExample.DelayQueue", 0); dispatch_async(delayQueue, ^{ // Wait 1 second sleep(1); dispatch_async(dispatch_get_main_queue(), ^{ self.label.text = [NSString stringWithFormat:@"Selected: %@", [self formatDate:self.monthPicker.date]]; }); }); } //- (void)setToThisMonth{ // self.monthPicker.date = [NSDate date]; // self.label.text = [NSString stringWithFormat:@"Selected: %@", [self formatDate:self.monthPicker.date]]; //} /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end