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

ActionSheetDatePicker target-action #27

Closed
mathiasgithub opened this issue Aug 28, 2014 · 5 comments
Closed

ActionSheetDatePicker target-action #27

mathiasgithub opened this issue Aug 28, 2014 · 5 comments

Comments

@mathiasgithub
Copy link

I'm having a hard time getting a custom cancel button and target-action to work with a datePicker. I just added setCancelButton to the example project below:

ActionSheetDatePicker *datePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Select a time" datePickerMode:UIDatePickerModeTime selectedDate:self.selectedTime target:self action:@selector(timeWasSelected:element:) origin:sender];

[datePicker setCancelButton:[[UIBarButtonItem alloc] initWithTitle:@"Not sure"  style:UIBarButtonItemStylePlain target:self action:@selector(datePickerCancelled:) ]];

datePicker.minuteInterval = minuteInterval;

[datePicker showActionSheetPicker];
@skywinder
Copy link
Owner

Hi, I don't understand your question.
Did you saw example project with custom button implementation?

@mathiasgithub
Copy link
Author

Thanks for your quick response! Sorry if I wasn't clear. I am basically trying to detect when a user presses cancel/hides the picker. It's working with string pickers, but not for date pickers. It basically never calls the selector.

I'm adding the code below straight into the example:

[datePicker setCancelButton:[[UIBarButtonItem alloc] initWithTitle:@"Not sure" style:UIBarButtonItemStylePlain target:self action:@selector(datePickerCancelled:) ]];

Here's the entire method:

-(IBAction)selectATime:(id)sender {

NSInteger minuteInterval = 5;
//clamp date
NSInteger referenceTimeInterval = (NSInteger)[self.selectedTime timeIntervalSinceReferenceDate];
NSInteger remainingSeconds = referenceTimeInterval % (minuteInterval *60);
NSInteger timeRoundedTo5Minutes = referenceTimeInterval - remainingSeconds;
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 setCancelButton:[[UIBarButtonItem alloc] initWithTitle:@"Not sure"  style:UIBarButtonItemStylePlain target:self action:@selector(datePickerCancelled:) ]];

datePicker.minuteInterval = minuteInterval;

[datePicker showActionSheetPicker];

}

@skywinder
Copy link
Owner

Ok! It really missed feature. Even 2!

  1. There is no way to set cancel action for ActionSheetDatePicker
  2. There is no way to override target-action for custom buttons.

I will fix it soon!

@skywinder
Copy link
Owner

Ok, I decide to not implement feature 2, because it's not generic and can cause bug in more complicated situations.
Please, use new method to achieve your purpose: (available since v.1.1.8)

ActionSheetDatePicker *datePicker = [[ActionSheetDatePicker alloc] initWithTitle:@"Select a time" 
                                                                      datePickerMode:UIDatePickerModeTime 
                                                                        selectedDate:self.selectedTime 
                                                                              target:self 
                                                                              action:@selector(timeWasSelected:element:) 
                                                                              origin:sender 
                                                                        cancelAction:@selector(datePickerCancelled:)];

@skywinder
Copy link
Owner

Feel free to reopen issue, if you still have questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants