From d25be0074d36328d9a43416d2fa6819d410971d3 Mon Sep 17 00:00:00 2001 From: Kirby Turner Date: Sat, 26 Sep 2015 07:50:02 -0400 Subject: [PATCH] Add alert convenience methods. --- WPSKit/UIKit/UIViewController+WPSKit.h | 7 +++++-- WPSKit/UIKit/UIViewController+WPSKit.m | 22 ++++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/WPSKit/UIKit/UIViewController+WPSKit.h b/WPSKit/UIKit/UIViewController+WPSKit.h index 74778cc..f2553e6 100644 --- a/WPSKit/UIKit/UIViewController+WPSKit.h +++ b/WPSKit/UIKit/UIViewController+WPSKit.h @@ -11,7 +11,10 @@ @interface UIViewController (WPSKit) - (void)wps_clearBackButtonTitle; -- (void)wps_setBackButtonTitle:(NSString *)title; -- (void)wps_setBackButtonChevron:(UIImage *)image; +- (void)wps_setBackButtonTitle:(nullable NSString *)title; +- (void)wps_setBackButtonChevron:(nullable UIImage *)image; + +- (void)wps_presentOkayAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message; +- (void)wps_presentOkayAlertWithError:(nullable NSError *)error; @end diff --git a/WPSKit/UIKit/UIViewController+WPSKit.m b/WPSKit/UIKit/UIViewController+WPSKit.m index 1e9ccb1..dc0cd4a 100644 --- a/WPSKit/UIKit/UIViewController+WPSKit.m +++ b/WPSKit/UIKit/UIViewController+WPSKit.m @@ -15,17 +15,35 @@ - (void)wps_clearBackButtonTitle [self wps_setBackButtonTitle:@""]; } -- (void)wps_setBackButtonTitle:(NSString *)title +- (void)wps_setBackButtonTitle:(nullable NSString *)title { UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:nil action:nil]; [[self navigationItem] setBackBarButtonItem:backButton]; } -- (void)wps_setBackButtonChevron:(UIImage *)image +- (void)wps_setBackButtonChevron:(nullable UIImage *)image { UINavigationBar *navBar = [[self navigationController] navigationBar]; [navBar setBackIndicatorImage:image]; [navBar setBackIndicatorTransitionMaskImage:image]; } +#pragma mark - Alert Helpers + +- (void)wps_presentOkayAlertWithTitle:(nullable NSString *)title message:(nullable NSString *)message +{ + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *okayAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"OK", @"WPSKit", @"Alert button title") style:UIAlertActionStyleDefault handler:nil]; + [alertController addAction:okayAction]; + + [self presentViewController:alertController animated:YES completion:nil]; +} + +- (void)wps_presentOkayAlertWithError:(nullable NSError *)error +{ + NSString *title = NSLocalizedStringFromTable(@"Error", @"WPSKit", @"Alert title."); + NSString *message = [error localizedDescription]; + [self wps_presentOkayAlertWithTitle:title message:message]; +} + @end