Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Add alert convenience methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirbyt committed Sep 26, 2015
1 parent 3b67836 commit d25be00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
7 changes: 5 additions & 2 deletions WPSKit/UIKit/UIViewController+WPSKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 20 additions & 2 deletions WPSKit/UIKit/UIViewController+WPSKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d25be00

Please sign in to comment.