-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
161308a
commit a9dcb87
Showing
3 changed files
with
66 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// RGAlertViewDelegate.h | ||
// | ||
// Created by Rok Gregorič on 27. 02. 14. | ||
// Copyright (c) 2014 Rok Gregorič. All rights reserved. | ||
// | ||
|
||
// USAGE: | ||
// | ||
// __weak UIViewController *wself = self; | ||
// self.alertViewDelegate = [RGAlertViewDelegate delegateWithHandler:^(NSInteger clickedButtonIndex) { | ||
// switch (clickedButtonIndex) { | ||
// case 0: { // No | ||
// [wself noTapped]; | ||
// } break; | ||
// case 1: { // Yes | ||
// [wself yesTapped]; | ||
// } break; | ||
// } | ||
// wself.alertViewDelegate = nil; | ||
// }]; | ||
// | ||
// UIAlertView *alert = [UIAlertView.alloc initWithTitle:@"Question" message:@"Are you sure?" delegate:self.alertViewDelegate cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil]; | ||
// [alert show]; | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
typedef void (^DelegateHandler)(NSInteger clickedButtonIndex); | ||
|
||
@interface RGAlertViewDelegate : NSObject <UIAlertViewDelegate> | ||
|
||
@property (nonatomic, copy) DelegateHandler delegateHandler; | ||
|
||
+ (instancetype)delegateWithHandler:(DelegateHandler)delegateHandler; | ||
|
||
@end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// RGAlertViewDelegate.m | ||
// | ||
// Created by Rok Gregorič on 27. 02. 14. | ||
// Copyright (c) 2014 Rok Gregorič. All rights reserved. | ||
// | ||
|
||
#import "RGAlertViewDelegate.h" | ||
|
||
@implementation RGAlertViewDelegate | ||
|
||
+ (instancetype)delegateWithHandler:(DelegateHandler)delegateHandler { | ||
RGAlertViewDelegate *alertViewDelegate = RGAlertViewDelegate.new; | ||
alertViewDelegate.delegateHandler = delegateHandler; | ||
return alertViewDelegate; | ||
} | ||
|
||
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { | ||
if (self.delegateHandler) { | ||
self.delegateHandler(buttonIndex); | ||
} | ||
} | ||
|
||
@end |