Skip to content

Commit

Permalink
Further support for countdown timer
Browse files Browse the repository at this point in the history
These changes should fix #72

Added an additional initialiser which allows to set the countdown timer
to an initial countdown interval.

Changed picker view configuration regarding the existence of countdown
timer.
  • Loading branch information
mgmart committed Oct 11, 2014
1 parent 4a0b4cc commit c7a951c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Pickers/ActionSheetDatePicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ typedef void(^ActionDateCancelBlock)(ActionSheetDatePicker *picker);

- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode selectedDate:(NSDate *)selectedDate target:(id)target action:(SEL)action origin:(id)origin cancelAction:(SEL)cancelAction;

// mgm: additional initializer which allows to set countdownduration
- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode countDownDuration:(NSTimeInterval)duration target:(id)target action:(SEL)action origin:(id)origin cancelAction:(SEL)cancelAction;


- (instancetype)initWithTitle:(NSString *)title
datePickerMode:(UIDatePickerMode)datePickerMode
selectedDate:(NSDate *)selectedDate
Expand Down
23 changes: 22 additions & 1 deletion Pickers/ActionSheetDatePicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ - (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePicke
return self;
}

// mgm: additional initializer which allows to set countdownduration
- (id)initWithTitle:(NSString *)title datePickerMode:(UIDatePickerMode)datePickerMode countDownDuration:(NSTimeInterval)duration target:(id)target action:(SEL)action origin:(id)origin cancelAction:(SEL)cancelAction
{
self = [super initWithTarget:target successAction:action cancelAction:cancelAction origin:origin];
if (self) {
self.title = title;
self.datePickerMode = datePickerMode;
self.duration = duration;
}
return self;
}

- (instancetype)initWithTitle:(NSString *)title
datePickerMode:(UIDatePickerMode)datePickerMode
selectedDate:(NSDate *)selectedDate
Expand All @@ -110,7 +122,15 @@ - (UIView *)configuredPickerView {
datePicker.timeZone = self.timeZone;
datePicker.locale = self.locale;

[datePicker setDate:self.selectedDate animated:NO];
// mgm: Set the datePicker according to mode
// if datepicker is set with a date in countdownmode then
// 1h is added to the initial countdown
if (self.datePickerMode == UIDatePickerModeCountDownTimer) {
datePicker.countDownDuration = self.duration;
} else {
[datePicker setDate:self.selectedDate animated:NO];
}

[datePicker addTarget:self action:@selector(eventForDatePicker:) forControlEvents:UIControlEventValueChanged];

//need to keep a reference to the picker so we can clear the DataSource / Delegate when dismissing (not used in this picker, but just in case somebody uses this as a template for another picker)
Expand All @@ -131,6 +151,7 @@ - (void)notifyTarget:(id)target didSucceedWithAction:(SEL)action origin:(id)orig
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (self.datePickerMode == UIDatePickerModeCountDownTimer) {
[target performSelector:action withObject:@(self.duration) withObject:origin];

} else {
[target performSelector:action withObject:self.selectedDate withObject:origin];
}
Expand Down

0 comments on commit c7a951c

Please sign in to comment.