MonthPickerViewController.m 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // MonthPickerViewController.m
  3. // RedAnt ERP Mobile
  4. //
  5. // Created by Ray on 8/18/15.
  6. // Copyright (c) 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. #import "MonthPickerViewController.h"
  9. @interface MonthPickerViewController ()
  10. @end
  11. @implementation MonthPickerViewController
  12. - (NSString*)formatDate:(NSDate *)date
  13. {
  14. // A convenience method that formats the date in Month-Year format
  15. NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
  16. formatter.dateFormat = @"MM/yyyy";
  17. return [formatter stringFromDate:date];
  18. }
  19. - (void)viewDidLoad {
  20. [super viewDidLoad];
  21. // Do any additional setup after loading the view.
  22. // I will be using the delegate here
  23. self.monthPicker.monthPickerDelegate = self;
  24. // Set the label to show the date
  25. // Some options to play around with
  26. self.monthPicker.maximumYear = 2050;
  27. self.monthPicker.minimumYear = 2015;
  28. self.monthPicker.yearFirst = YES;
  29. //
  30. // NSDateComponents* dateParts = [[NSDateComponents alloc] init];
  31. //
  32. // dateParts.month = 10;
  33. // dateParts.year = 2009;
  34. self.monthPicker.date = self.current_date;
  35. // self.label.text = [NSString stringWithFormat:@"Selected: %@", [self formatDate:self.monthPicker.date]];
  36. self.label.text = [NSString stringWithFormat:@"Selected: %@", [self formatDate:self.monthPicker.date]];
  37. }
  38. - (IBAction)onSetValue:(id)sender {
  39. // if(self.dirty == false)
  40. // return;
  41. if (self.delegate && [self.delegate respondsToSelector:@selector(MPValueChanged:indexPath:)]) {
  42. [self.delegate MPValueChanged: [self formatDate:self.monthPicker.date] indexPath:self.updatePosition];
  43. }
  44. [self.navigationController popViewControllerAnimated:false];
  45. // if(self.returnValue)
  46. // self.returnValue(self.cadedate);
  47. }
  48. - (void)didReceiveMemoryWarning {
  49. [super didReceiveMemoryWarning];
  50. // Dispose of any resources that can be recreated.
  51. }
  52. - (void)monthPickerWillChangeDate:(SRMonthPicker *)monthPicker
  53. {
  54. // Show the date is changing (with a 1 second wait mimicked)
  55. self.label.text = [NSString stringWithFormat:@"Was: %@", [self formatDate:monthPicker.date]];
  56. }
  57. - (void)monthPickerDidChangeDate:(SRMonthPicker *)monthPicker
  58. {
  59. // All this GCD stuff is here so that the label change on -[self monthPickerWillChangeDate] will be visible
  60. dispatch_queue_t delayQueue = dispatch_queue_create("com.simonrice.SRMonthPickerExample.DelayQueue", 0);
  61. dispatch_async(delayQueue, ^{
  62. // Wait 1 second
  63. sleep(1);
  64. dispatch_async(dispatch_get_main_queue(), ^{
  65. self.label.text = [NSString stringWithFormat:@"Selected: %@", [self formatDate:self.monthPicker.date]];
  66. });
  67. });
  68. }
  69. //- (void)setToThisMonth{
  70. // self.monthPicker.date = [NSDate date];
  71. // self.label.text = [NSString stringWithFormat:@"Selected: %@", [self formatDate:self.monthPicker.date]];
  72. //}
  73. /*
  74. #pragma mark - Navigation
  75. // In a storyboard-based application, you will often want to do a little preparation before navigation
  76. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  77. // Get the new view controller using [segue destinationViewController].
  78. // Pass the selected object to the new view controller.
  79. }
  80. */
  81. @end