Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added workaround for a bug in UIDatePicker in count down mode. #105

Merged
merged 24 commits into from
Dec 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
12aba9a
Added minimumDate and maximumDate to contructor of ActionSheetDatePicker
emmanuelay Nov 17, 2014
0b4f561
Added additional constructors for min/maxdate
emmanuelay Nov 17, 2014
81abf99
Added workaround for a bug in UIDatePicker in count down mode.
tomaskraina Nov 30, 2014
6f9838f
Merge pull request #107 from bitdeli-chef/master
skywinder Dec 1, 2014
3f44f1d
Merge branch 'master' of https://github.com/tomaskraina/ActionSheetPi…
skywinder Dec 2, 2014
f90c907
add countDown picker example
skywinder Dec 2, 2014
b3668ab
Merge branch 'max-min-datepicker' of https://github.com/emmanuelay/Ac…
skywinder Dec 2, 2014
bbde848
storyboard update
skywinder Dec 2, 2014
8a1c316
Merge branch 'emmanuelay-max-min-datepicker'
skywinder Dec 2, 2014
1ec2417
Merge branch 'master' into develop
skywinder Dec 2, 2014
11ca307
add default init tests
skywinder Dec 2, 2014
be31c7a
fix for library depedency http://stackoverflow.com/questions/5427396…
skywinder Dec 2, 2014
f567b38
fix warnings
skywinder Dec 2, 2014
bbd8e2f
Modified a test case that shows bug in UIDatePicket
Dec 2, 2014
35bf4b6
add new test case
skywinder Dec 2, 2014
5bc5ff4
remove dead link
skywinder Dec 2, 2014
6abb206
add test for new init methods in #98
skywinder Dec 2, 2014
458ada7
Merge branch 'feature/test-for-98' into develop
skywinder Dec 2, 2014
e2aafa2
add delay to test
skywinder Dec 2, 2014
861b849
Merge branch 'develop' into tomaskraina-master
skywinder Dec 2, 2014
794f0d6
fix
skywinder Dec 2, 2014
d1eb343
add addtitional check for value
skywinder Dec 2, 2014
effa050
Updated workaround for bug in UIDatePicker
Dec 3, 2014
f85ecce
merge tomaskraina-master into master
Dec 3, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 78 additions & 28 deletions ObjC-Example/ActionSheetPicker Tests/ActionSheetDatePickerTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

#import <XCTest/XCTest.h>
#import <CoreActionSheetPicker/CoreActionSheetPicker.h>
#import <CoreActionSheetPicker/ActionSheetDatePicker.h>
#import "AbstractActionSheetPicker+CustomButton.h"

static const int countdownTestInt = 360;
UIView *origin;
UIView *origin;

@interface ActionSheetDatePickerTestCase : XCTestCase
@property(nonatomic, strong) ActionSheetDatePicker *actionSheetDatePicker;
Expand All @@ -22,35 +23,74 @@ @implementation ActionSheetDatePickerTestCase
NSString *_title;
}

+(void)setUp{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *topView = window.rootViewController.view;
origin = topView;
+ (void)setUp
{
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *topView = window.rootViewController.view;
origin = topView;
}

- (void)setUp {
- (void)setUp
{
[super setUp];
_title = @"Title";
_title = @"Title";
_actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Test title" datePickerMode:UIDatePickerModeDate selectedDate:[NSDate date] target:nil action:nil origin:origin cancelAction:nil];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testInitPicker
{
_actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTarget:self successAction:@selector(exampleSelector) cancelAction:@selector(exampleSelector) origin:origin];
XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testInitPicker2
{
_actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" datePickerMode:UIDatePickerModeCountDownTimer selectedDate:[NSDate date] doneBlock:nil cancelBlock:nil origin:origin];
XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testInitPicker3
{
_actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" datePickerMode:UIDatePickerModeCountDownTimer selectedDate:[NSDate date] target:self action:@selector(exampleSelector) origin:origin];
XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testInitPicker4
{
_actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" datePickerMode:UIDatePickerModeCountDownTimer selectedDate:NSDate.date target:self action:@selector(exampleSelector) origin:origin cancelAction:@selector(exampleSelector)];
XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testInitPicker5
{
_actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" datePickerMode:UIDatePickerModeCountDownTimer selectedDate:[NSDate date] minimumDate:[NSDate date] maximumDate:[NSDate date] target:self action:@selector(exampleSelector) origin:origin];
XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testInitPicker6
{
_actionSheetDatePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" datePickerMode:UIDatePickerModeCountDownTimer selectedDate:NSDate.date minimumDate:NSDate.date maximumDate:NSDate.date target:self action:@selector(exampleSelector) cancelAction:@selector(exampleSelector) origin:origin];
XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithCustomActionBlockOnButton
{
NSString *custom_title = @"Custom label:";

[_actionSheetDatePicker addCustomButtonWithTitle:custom_title actionBlock:^{
NSLog(@"Test block invoked");
}];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

Expand All @@ -60,7 +100,7 @@ - (void)testPickerWithCustomActionBlockOnButtonAndNilString
NSLog(@"Test block invoked");
}];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
Expand All @@ -70,19 +110,19 @@ - (void)testPickerWithNilCustomActionBlockOnButton
{
[_actionSheetDatePicker addCustomButtonWithTitle:_title actionBlock:nil];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithNilCustomActionBlockOnButtonAndNilString
{
[_actionSheetDatePicker addCustomButtonWithTitle:nil actionBlock:nil];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

Expand All @@ -100,39 +140,39 @@ - (void)testPickerWithCustomActionSelectorOnButtonAndNilString
{
[_actionSheetDatePicker addCustomButtonWithTitle:nil target:self selector:@selector(exampleSelector)];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithNilCustomActionSelectorOnButton
{
[_actionSheetDatePicker addCustomButtonWithTitle:_title target:self selector:nil];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithCustomActionSelectorOnButtonAndNilTarget
{
[_actionSheetDatePicker addCustomButtonWithTitle:_title target:nil selector:@selector(exampleSelector)];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

- (void)testPickerWithNilCustomActionSelectorOnButtonNilTargetAndNilString
{
[_actionSheetDatePicker addCustomButtonWithTitle:nil target:nil selector:nil];
[_actionSheetDatePicker showActionSheetPicker];

[_actionSheetDatePicker pressFirstCustomButton];

XCTAssertNotNil(_actionSheetDatePicker);
}

Expand All @@ -141,7 +181,12 @@ - (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];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[NSThread sleepForTimeInterval:0.5f];
dispatch_async(dispatch_get_main_queue(), ^{
[_actionSheetDatePicker pressDoneButton];
});
});

XCTAssertNotNil(_actionSheetDatePicker);
}
Expand All @@ -150,12 +195,17 @@ - (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];
XCTAssertEqualObjects(@(picker.countDownDuration), @(countdownTestInt));
} cancelBlock:nil origin:origin];

_actionSheetDatePicker.countDownDuration = countdownTestInt;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[NSThread sleepForTimeInterval:0.5f];
dispatch_async(dispatch_get_main_queue(), ^{
[_actionSheetDatePicker pressDoneButton];
});
});
[_actionSheetDatePicker showActionSheetPicker];
UIDatePicker *picker = (UIDatePicker *)_actionSheetDatePicker.pickerView;
[_actionSheetDatePicker pressDoneButton];

XCTAssertNotNil(_actionSheetDatePicker);
}
Expand Down
4 changes: 1 addition & 3 deletions ObjC-Example/ActionSheetPicker.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@
1C9444BE197B1C2F005F495B /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = "<group>"; };
1C9444C2197B1C2F005F495B /* ActionSheetPicker Tests-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "ActionSheetPicker Tests-Prefix.pch"; sourceTree = "<group>"; };
1C9444C8197B1C75005F495B /* ActionSheetCustomPickerTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ActionSheetCustomPickerTestCase.m; sourceTree = "<group>"; };
1CA808AD1A25D01A004252BA /* CoreActionSheetPicker.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreActionSheetPicker.framework; path = "../CoreActionSheetPicker/build/Debug-iphoneos/CoreActionSheetPicker.framework"; sourceTree = "<group>"; };
1CA808AF1A25D0D1004252BA /* CoreActionSheetPicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; name = CoreActionSheetPicker.framework; path = "/Users/petrkorolev/Library/Developer/Xcode/DerivedData/Example-heqowupkotascefopnknxqwrfsgq/Build/Products/Debug-iphoneos/CoreActionSheetPicker.framework"; sourceTree = "<absolute>"; };
1CA808AF1A25D0D1004252BA /* CoreActionSheetPicker.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = CoreActionSheetPicker.framework; sourceTree = BUILT_PRODUCTS_DIR; };
1CA808B31A25DD6A004252BA /* CoreActionSheetPicker.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = CoreActionSheetPicker.framework; sourceTree = "<group>"; };
1CD15A2F192C7A0A00B28881 /* ActionSheetPicker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ActionSheetPicker.app; sourceTree = BUILT_PRODUCTS_DIR; };
1CFCACFC1980FA320056A594 /* Storyboard.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Storyboard.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -212,7 +211,6 @@
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
isa = PBXGroup;
children = (
1CA808AD1A25D01A004252BA /* CoreActionSheetPicker.framework */,
1CA808B31A25DD6A004252BA /* CoreActionSheetPicker.framework */,
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */,
1D30AB110D05D00D00671497 /* Foundation.framework */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
@property (nonatomic, strong) IBOutlet UITextField *animalTextField;
@property (nonatomic, strong) IBOutlet UITextField *dateTextField;
@property (nonatomic, strong) IBOutlet UITextField *timeTextField;
@property (strong, nonatomic) IBOutlet UITextField *counDownTextField;

@property (nonatomic, strong) NSArray *animals;
@property (nonatomic, assign) NSInteger selectedIndex;
Expand Down
60 changes: 44 additions & 16 deletions ObjC-Example/Example/Classes/ActionSheetPickerViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,35 +87,58 @@ - (IBAction)selectALocale:(UIControl *)sender {
NSLog(@"Locale Picker Canceled");
};
ActionSheetLocalePicker *picker = [[ActionSheetLocalePicker alloc] initWithTitle:@"Select Locale:" initialSelection:[[NSTimeZone alloc] initWithName:@"Antarctica/McMurdo"] doneBlock:done cancelBlock:cancel origin:sender];

[picker addCustomButtonWithTitle:@"My locale" value:[NSTimeZone localTimeZone]];
__weak UIControl *weakSender = sender;
[picker addCustomButtonWithTitle:@"Hide" actionBlock:^{
if ([weakSender respondsToSelector:@selector(setText:)]) {
[weakSender performSelector:@selector(setText:) withObject:[NSTimeZone localTimeZone].name];
}
}];

picker.hideCancel = YES;
[picker showActionSheetPicker];
}



- (IBAction)selectADate:(UIControl *)sender {
_actionSheetPicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" datePickerMode:UIDatePickerModeDate selectedDate:self.selectedDate target:self action:@selector(dateWasSelected:element:) origin:sender];
_actionSheetPicker = [[ActionSheetDatePicker alloc] initWithTitle:@"" datePickerMode:UIDatePickerModeDate selectedDate:self.selectedDate minimumDate:nil maximumDate:nil target:self action:@selector(dateWasSelected:element:) origin:sender];
[self.actionSheetPicker addCustomButtonWithTitle:@"Today" value:[NSDate date]];
[self.actionSheetPicker addCustomButtonWithTitle:@"Yesterday" value:[[NSDate date] TC_dateByAddingCalendarUnits:NSDayCalendarUnit amount:-1]];
[self.actionSheetPicker addCustomButtonWithTitle:@"Yesterday" value:[[NSDate date] TC_dateByAddingCalendarUnits:NSCalendarUnitDay amount:-1]];
self.actionSheetPicker.hideCancel = YES;
[self.actionSheetPicker showActionSheetPicker];
}

- (IBAction)selectACountdown:(UIControl *)sender {

_actionSheetPicker = [[ActionSheetDatePicker alloc] initWithTitle:@""
datePickerMode:UIDatePickerModeCountDownTimer
selectedDate:nil
doneBlock:^(ActionSheetDatePicker *picker, id selectedDate, id origin) {

NSLog(@"selectedDate: %@", selectedDate);
self.counDownTextField.text = [selectedDate stringValue];
NSLog(@"picker.countDownDuration, %f", picker.countDownDuration);
self.counDownTextField.text = [NSString stringWithFormat:@"%f", picker.countDownDuration];

} cancelBlock:^(ActionSheetDatePicker *picker) {

NSLog(@"Cancel clicked");

} origin:sender];

[(ActionSheetDatePicker *) _actionSheetPicker setCountDownDuration:120];
self.actionSheetPicker.hideCancel = YES;
[self.actionSheetPicker showActionSheetPicker];
}



-(IBAction)selectATime:(id)sender {



NSInteger minuteInterval = 5;
//clamp date
NSInteger referenceTimeInterval = (NSInteger)[self.selectedTime timeIntervalSinceReferenceDate];
Expand All @@ -124,9 +147,9 @@ -(IBAction)selectATime:(id)sender {
if(remainingSeconds>((minuteInterval*60)/2)) {/// round up
timeRoundedTo5Minutes = referenceTimeInterval +((minuteInterval*60)-remainingSeconds);
}

self.selectedTime = [NSDate dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)timeRoundedTo5Minutes];

ActionSheetDatePicker *datePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Select a time" datePickerMode:UIDatePickerModeTime selectedDate:self.selectedTime target:self action:@selector(timeWasSelected:element:) origin:sender];
datePicker.minuteInterval = minuteInterval;
[datePicker addCustomButtonWithTitle:@"value" value:[NSDate date]];
Expand All @@ -147,14 +170,14 @@ - (IBAction)selectAMeasurement:(UIControl *)sender {
}

- (IBAction)selectAMusicalScale:(UIControl *)sender {

ActionSheetPickerCustomPickerDelegate *delg = [[ActionSheetPickerCustomPickerDelegate alloc] init];

NSNumber *yass1 = @1;
NSNumber *yass2 = @2;

NSArray *initialSelections = @[yass1, yass2];

[ActionSheetCustomPicker showPickerWithTitle:@"Select Key & Scale" delegate:delg showCancelButton:NO origin:sender
initialSelections:initialSelections];
}
Expand Down Expand Up @@ -225,21 +248,26 @@ - (UIFont *)getRandomFont

- (void)animalWasSelected:(NSNumber *)selectedIndex element:(id)element {
self.selectedIndex = [selectedIndex intValue];

//may have originated from textField or barButtonItem, use an IBOutlet instead of element
self.animalTextField.text = (self.animals)[(NSUInteger) self.selectedIndex];
}

- (void)dateWasSelected:(NSDate *)selectedDate element:(id)element {
self.selectedDate = selectedDate;

//may have originated from textField or barButtonItem, use an IBOutlet instead of element
self.dateTextField.text = [self.selectedDate description];
}

- (void)countDownWasSelected:(NSNumber *)selectedDate element:(id)element {
//may have originated from textField or barButtonItem, use an IBOutlet instead of element
self.counDownTextField.text = selectedDate.stringValue;
}

-(void)timeWasSelected:(NSDate *)selectedTime element:(id)element {
self.selectedTime = selectedTime;

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"h:mm a"];
self.timeTextField.text = [dateFormatter stringFromDate:selectedTime];
Expand Down
2 changes: 1 addition & 1 deletion ObjC-Example/Example/Classes/TestTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
// };
// NSArray *colors = @[@"Red", @"Green", @"Blue", @"Orange"];
// [ActionSheetStringPicker showPickerWithTitle:@"Select a Block" rows:colors initialSelection:0 doneBlock:done cancelBlock:cancel origin:sender];
ActionSheetDatePicker *datePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Select a time" datePickerMode:UIDatePickerModeTime selectedDate:[NSDate date] target:self action:@selector(timeWasSelected:element:) origin:sender];
ActionSheetDatePicker *datePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Select a time" datePickerMode:UIDatePickerModeTime selectedDate:[NSDate date] minimumDate:nil maximumDate:nil target:self action:@selector(timeWasSelected:element:) origin:sender];
datePicker.minuteInterval = 5;
[datePicker showActionSheetPicker];
}
Expand Down
Loading