-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIAlertView+IABlocks.h
More file actions
117 lines (91 loc) · 5.1 KB
/
UIAlertView+IABlocks.h
File metadata and controls
117 lines (91 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// UIAlertView+IABlocks.h
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <http://unlicense.org>
//
#import <UIKit/UIKit.h>
/**
The block for UIAlertView events.
@param alert The alert view that fired the event.
@param buttonIndex The index of the button related to the event. May be -1 if it does not apply.
*/
typedef void (^IAAlertViewHandler)(UIAlertView* alert, NSInteger buttonIndex);
/**
This category adds support for blocks to UIAlertViews, making it unnecessary to use delegates.
Using the initializer initWithTitle:message:cancelButtonTitle:otherButtonTitles:... automatically enables
blocks for the alert view, but they can also be toggled on or of using the blocksEnabled property. Note
that when blocks are enabled you SHOULD NOT set the delegate to something else. This implementation
depends on a private class that acts as the delegate when blocks are enabled. Setting a different delegate
will have undefined results.
*/
@interface UIAlertView (IABlocks)
/**
Convenience method for initializing an alert view with blocks enabled.
@param title The string that appears in the receiver’s title bar.
@param message Descriptive text that provides more details than the title.
@param cancelButtonTitle The title of the cancel button or nil if there is no cancel button.
Using this argument is equivalent to setting the cancel button index to the value returned by invoking addButtonWithTitle: specifying this title.
@param otherButtonTitles The title of another button.
Using this argument is equivalent to invoking addButtonWithTitle: with this title to add more buttons.
@param ... Titles of additional buttons to add to the receiver, terminated with nil.
@return Newly initialized alert view with blocks enabled.
*/
- (id)initWithTitle:(NSString*)title message:(NSString*)message cancelButtonTitle:(NSString*)cancelButtonTitle otherButtonTitles:(NSString*)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATION;
/** A Boolean value indicating whether blocks are enabled. */
@property (nonatomic, getter = isBlocksEnabled) BOOL blocksEnabled;
/**
The cancel handler will be called when the alert is cancelled, either by the system or
by the user tapping the cancel button.
The buttonIndex parameter of the handler is -1 if the alert is cancelled by the system, or
equal to cancelButtonIndex if the user tapped the cancel button.
See [UIAlertViewDelegate alertViewCancel:].
*/
@property (copy, nonatomic) IAAlertViewHandler cancelHandler;
/** See [UIAlertViewDelegate alertViewShouldEnableFirstOtherButton:]. */
@property (copy, nonatomic) BOOL (^shouldEnableFirstOtherButtonHandler)(UIAlertView* alert);
/** See [UIAlertViewDelegate alertView:clickedButtonAtIndex:]. */
@property (copy, nonatomic) IAAlertViewHandler buttonHandler;
/** See [UIAlertViewDelegate willPresentAlertView:]. */
@property (copy, nonatomic) IAAlertViewHandler willPresentHandler;
/** See [UIAlertViewDelegate didPresentAlertView:]. */
@property (copy, nonatomic) IAAlertViewHandler didPresentHandler;
/** See [UIAlertViewDelegate alertView:willDismissWithButtonIndex:]. */
@property (copy, nonatomic) IAAlertViewHandler willDismissHandler;
/** See [UIAlertViewDelegate alertView:didDismissWithButtonIndex:]. */
@property (copy, nonatomic) IAAlertViewHandler didDismissHandler;
/**
Returns the handler for the button at the given index.
@param buttonIndex The index of the button. The button indices start at 0.
@return The handler for the button specified by index buttonIndex.
*/
- (IAAlertViewHandler)handlerForButtonAtIndex:(NSInteger)buttonIndex;
/**
Sets the handler for the button at the given index.
@param handler The handler that will be called when the button is tapped.
@param buttonIndex The index of the button. The button indices start at 0.
*/
- (void)setHandler:(IAAlertViewHandler)handler forButtonAtIndex:(NSInteger)buttonIndex;
@end