-
Notifications
You must be signed in to change notification settings - Fork 165
Usage
The first thing you need to do is importing RMDateSelectionViewController in your view controller.
#import "RMDateSelectionViewController.h"
import RMDateSelectionViewController
After that you need to create a select and a cancel action.
RMAction<UIDatePicker *> *selectAction = [RMAction<UIDatePicker *> actionWithTitle:@"Select" style:RMActionStyleDone andHandler:^(RMActionController<UIDatePicker *> *controller) {
NSLog(@"Successfully selected date: %@", controller.contentView.date);
}];
RMAction<UIDatePicker *> *cancelAction = [RMAction<UIDatePicker *> actionWithTitle:@"Cancel" style:RMActionStyleCancel andHandler:^(RMActionController<UIDatePicker *> *controller) {
NSLog(@"Date selection was canceled");
}];
let selectAction = RMAction<UIDatePicker>(title: "Select", style: RMActionStyle.done) { controller in
print("Successfully selected date: ", controller.contentView.date);
}
let cancelAction = RMAction<UIDatePicker>(title: "Cancel", style: RMActionStyle.cancel) { _ in
print("Date selection was canceled")
}
In the last step you create a RMDateSelectionViewController instance, set select and cancel block and present the RMDateSelectionViewController instance
RMDateSelectionViewController *dateSelectionController = [RMDateSelectionViewController actionControllerWithStyle:RMActionControllerStyleWhite title:@"Test" message:@"This is a test message.\nPlease choose a date and press 'Select' or 'Cancel'." selectAction:selectAction andCancelAction:cancelAction];
//Now just present the date selection controller using the standard iOS presentation method
[self presentViewController:dateSelectionController animated:YES completion:nil];
let actionController = RMDateSelectionViewController(style: .white, title: "Test", message: "This is a test message.\nPlease choose a date and press 'Select' or 'Cancel'.", select: selectAction, andCancel: cancelAction)!;
//Now just present the date selection controller using the standard iOS presentation method
present(actionController, animated: true, completion: nil)
The following example combines the above code into one snippet
- (IBAction)openDateSelectionController:(id)sender {
RMAction<UIDatePicker *> *selectAction = [RMAction<UIDatePicker *> actionWithTitle:@"Select" style:RMActionStyleDone andHandler:^(RMActionController<UIDatePicker *> *controller) {
NSLog(@"Successfully selected date: %@", controller.contentView.date);
}];
RMAction<UIDatePicker *> *cancelAction = [RMAction<UIDatePicker *> actionWithTitle:@"Cancel" style:RMActionStyleCancel andHandler:^(RMActionController<UIDatePicker *> *controller) {
NSLog(@"Date selection was canceled");
}];
RMDateSelectionViewController *dateSelectionController = [RMDateSelectionViewController actionControllerWithStyle:RMActionControllerStyleWhite title:@"Test" message:@"This is a test message.\nPlease choose a date and press 'Select' or 'Cancel'." selectAction:selectAction andCancelAction:cancelAction];
//Now just present the date selection controller using the standard iOS presentation method
[self presentViewController:dateSelectionController animated:YES completion:nil];
}
func openDateSelectionViewController() {
let selectAction = RMAction<UIDatePicker>(title: "Select", style: RMActionStyle.done) { controller in
print("Successfully selected date: ", controller.contentView.date);
}
let cancelAction = RMAction<UIDatePicker>(title: "Cancel", style: RMActionStyle.cancel) { _ in
print("Date selection was canceled")
}
let actionController = RMDateSelectionViewController(style: .white, title: "Test", message: "This is a test message.\nPlease choose a date and press 'Select' or 'Cancel'.", select: selectAction, andCancel: cancelAction)!;
//Now just present the date selection controller using the standard iOS presentation method
present(actionController, animated: true, completion: nil)
}
There are some advanced options you might want to set before presenting RMDateSelectionViewController
There are some some more options inherited from RMActionController. These options are described in (How to user RMActionController)[https://github.com/CooperRS/RMActionController/wiki/Usage] (links to the wiki of RMActionController).
As with RMActionController, you may use RMDateSelectionViewController in both your main application and your action extension showing an user interface. RMDateSelectionViewController only uses APIs that are safe to be used in extensions, too.