Skip to content

Commit

Permalink
add method for creation UIAlertController with AlertStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
RouterInViewModel committed Jan 30, 2016
1 parent 817af67 commit 9c9598e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
16 changes: 16 additions & 0 deletions Pod/Classes/UIViewController+HRAlertViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@
*/
@interface UIViewController (HRAlertView)

/**
* Method for creating UIAlertController with AlertStyle.
*
* @param title Title property in alert.
* @param message Description property in alert.
* @param buttonTitles NSArray<NSString *> * with titles of buttons.
* @param handler Block, which called if buttons in alert is tapped. 2 params: action of button and index of button.
*
* @return UIAlertController instance.
*
*/
-(nonnull UIAlertController *)hrAlertWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
buttonsTitles:(nullable NSArray<NSString *> *)buttonTitles
andHandler:(void (^ __nullable)(UIAlertAction * _Nullable action, NSInteger indexOfAction))handler;

/**
* Method for showing UIAlertController with AlertStyle.
*
Expand Down
20 changes: 16 additions & 4 deletions Pod/Classes/UIViewController+HRAlertViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

@implementation UIViewController (HRAlertView)

-(void)hrShowAlertWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
buttonsTitles:(NSArray<NSString *> *)buttonTitles
andHandler:(void (^ __nullable)(UIAlertAction * _Nullable action, NSInteger indexOfAction))handler {
-(nonnull UIAlertController *)hrAlertWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
buttonsTitles:(nullable NSArray<NSString *> *)buttonTitles
andHandler:(void (^ __nullable)(UIAlertAction * _Nullable action, NSInteger indexOfAction))handler {
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title
message:message
preferredStyle:UIAlertControllerStyleAlert];
Expand All @@ -28,6 +28,18 @@ -(void)hrShowAlertWithTitle:(nullable NSString *)title
}];
[alertController addAction:action];
}
return alertController;
}


-(void)hrShowAlertWithTitle:(nullable NSString *)title
message:(nullable NSString *)message
buttonsTitles:(NSArray<NSString *> *)buttonTitles
andHandler:(void (^ __nullable)(UIAlertAction * _Nullable action, NSInteger indexOfAction))handler {
UIAlertController *alertController = [self hrAlertWithTitle:title
message:message
buttonsTitles:buttonTitles
andHandler:handler];
[self presentViewController:alertController animated:YES completion:nil];
}

Expand Down

0 comments on commit 9c9598e

Please sign in to comment.