diff --git a/ObjC-Example/ActionSheetPicker Tests/ActionSheetDatePickerTestCase.m b/ObjC-Example/ActionSheetPicker Tests/ActionSheetDatePickerTestCase.m index 30b03ba96..2efe80f61 100644 --- a/ObjC-Example/ActionSheetPicker Tests/ActionSheetDatePickerTestCase.m +++ b/ObjC-Example/ActionSheetPicker Tests/ActionSheetDatePickerTestCase.m @@ -9,6 +9,8 @@ #import #import #import "AbstractActionSheetPicker+CustomButton.h" + +static const int countdownTestInt = 360; UIView *origin; @interface ActionSheetDatePickerTestCase : XCTestCase @@ -134,6 +136,35 @@ - (void)testPickerWithNilCustomActionSelectorOnButtonNilTargetAndNilString XCTAssertNotNil(_actionSheetDatePicker); } +- (void)testPickerCountDownTimerModeValueWithSelector +{ + _actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Test title" datePickerMode:UIDatePickerModeCountDownTimer selectedDate:nil target:self action:@selector(countDownTest:) origin:origin cancelAction:nil]; + _actionSheetDatePicker.countDownDuration = countdownTestInt; + [_actionSheetDatePicker showActionSheetPicker]; + [_actionSheetDatePicker pressDoneButton]; + + XCTAssertNotNil(_actionSheetDatePicker); +} + +- (void)testPickerCountDownTimerModeValueWithBlock +{ + _actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Test" datePickerMode:UIDatePickerModeCountDownTimer selectedDate:nil doneBlock:^(ActionSheetDatePicker *picker, id selectedDate, id origin) { + XCTAssertEqualObjects(selectedDate, @(countdownTestInt)); + } cancelBlock:nil origin:origin]; + + _actionSheetDatePicker.countDownDuration = countdownTestInt; + [_actionSheetDatePicker showActionSheetPicker]; + UIDatePicker *picker = (UIDatePicker *)_actionSheetDatePicker.pickerView; + [_actionSheetDatePicker pressDoneButton]; + + XCTAssertNotNil(_actionSheetDatePicker); +} + +- (void)countDownTest:(NSNumber *)number +{ + XCTAssertEqualObjects(number, @(countdownTestInt)); +} + - (void)exampleSelector { NSLog(@"Test selector invoked"); diff --git a/ObjC-Example/Example/Classes/AbstractActionSheetPicker+CustomButton.h b/ObjC-Example/Example/Classes/AbstractActionSheetPicker+CustomButton.h index e1d7d5e2d..b370d5193 100644 --- a/ObjC-Example/Example/Classes/AbstractActionSheetPicker+CustomButton.h +++ b/ObjC-Example/Example/Classes/AbstractActionSheetPicker+CustomButton.h @@ -9,4 +9,5 @@ - (void)pressFirstCustomButton; +- (void)pressDoneButton; @end \ No newline at end of file diff --git a/ObjC-Example/Example/Classes/AbstractActionSheetPicker+CustomButton.m b/ObjC-Example/Example/Classes/AbstractActionSheetPicker+CustomButton.m index 0e941a446..9075956d4 100644 --- a/ObjC-Example/Example/Classes/AbstractActionSheetPicker+CustomButton.m +++ b/ObjC-Example/Example/Classes/AbstractActionSheetPicker+CustomButton.m @@ -18,4 +18,14 @@ - (void)pressFirstCustomButton ); } +- (void)pressDoneButton +{ + //6 items in _actionSheetDatePicker.toolbar.items : [ cancel - custom - separator - title - separator - done ] + //So, check custom button: + UIBarButtonItem *customBarButton = self.toolbar.items[4]; + SuppressPerformSelectorLeakWarning ( + [customBarButton.target performSelector:customBarButton.action withObject:customBarButton]; + ); +} + @end \ No newline at end of file diff --git a/Pickers/ActionSheetDatePicker.m b/Pickers/ActionSheetDatePicker.m index 164861712..93ba6989a 100755 --- a/Pickers/ActionSheetDatePicker.m +++ b/Pickers/ActionSheetDatePicker.m @@ -126,7 +126,7 @@ - (void)notifyTarget:(id)target didSucceedWithAction:(SEL)action origin:(id)orig if (self.onActionSheetDone) { if (self.datePickerMode == UIDatePickerModeCountDownTimer) - self.onActionSheetDone(self, @(self.countDownDuration), origin); + self.onActionSheetDone(self, @(((UIDatePicker *)self.pickerView).countDownDuration), origin); else self.onActionSheetDone(self, self.selectedDate, origin); @@ -136,7 +136,7 @@ - (void)notifyTarget:(id)target didSucceedWithAction:(SEL)action origin:(id)orig #pragma clang diagnostic push #pragma clang diagnostic ignored "-Warc-performSelector-leaks" if (self.datePickerMode == UIDatePickerModeCountDownTimer) { - [target performSelector:action withObject:@(self.countDownDuration) withObject:origin]; + [target performSelector:action withObject:@(((UIDatePicker *)self.pickerView).countDownDuration) withObject:origin]; } else { [target performSelector:action withObject:self.selectedDate withObject:origin];