PageRenderTime 18ms CodeModel.GetById 9ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/BlocksKit/UIActionSheet+BlocksKit.h

http://github.com/zwaldowski/BlocksKit
C++ Header | 128 lines | 15 code | 18 blank | 95 comment | 0 complexity | 0eb3ee761b0067c952f66f463f319742 MD5 | raw file
  1//
  2//  UIActionSheet+BlocksKit.h
  3//  %PROJECT
  4//
  5
  6#import "BKGlobals.h"
  7
  8/** UIActionSheet without delegates!
  9
 10 This set of extensions and convenience classes allows
 11 for an instance of UIAlertView without the implementation
 12 of a delegate.  Any time you instantiate a UIAlertView
 13 using the methods here, you must add buttons using
 14 addButtonWithTitle:handler: to make sure nothing breaks.
 15
 16 A typical invocation might go like this:
 17	 UIActionSheet *testSheet = [UIActionSheet actionSheetWithTitle:@"Please select one."];
 18	 [testSheet addButtonWithTitle:@"Zip" handler:^{ NSLog(@"Zip!"); }];
 19	 [testSheet addButtonWithTitle:@"Zap" handler:^{ NSLog(@"Zap!"); }];
 20	 [testSheet addButtonWithTitle:@"Zop" handler:^{ NSLog(@"Zop!"); }];
 21	 [testSheet setDestructiveButtonWithTitle:@"No!" handler:^{ NSLog(@"Fine!"); }];
 22	 [testSheet setCancelButtonWithTitle:nil handler:^{ NSLog(@"Never mind, then!"); }];
 23	 [testSheet showInView:self.view];
 24
 25 Includes code by the following:
 26
 27 - Landon Fuller, "Using Blocks".  <http://landonf.bikemonkey.org>.
 28 - Peter Steinberger. <https://github.com/steipete>.   2011. MIT.
 29 - Zach Waldowski.	<https://github.com/zwaldowski>. 2011. MIT.
 30
 31 @warning UIActionSheet is only available on iOS or in a Mac app using Chameleon.
 32 */
 33@interface UIActionSheet (BlocksKit) <UIActionSheetDelegate>
 34
 35///-----------------------------------
 36/// @name Creating action sheets
 37///-----------------------------------
 38
 39/** Creates and returns a new action sheet with only a title and cancel button.
 40
 41 @param title The header of the action sheet.
 42 @return A newly created action sheet.
 43 */
 44+ (id)actionSheetWithTitle:(NSString *)title;
 45
 46/** Returns a configured action sheet with only a title and cancel button.
 47
 48 @param title The header of the action sheet.
 49 @return An instantiated actionSheet.
 50 */
 51- (id)initWithTitle:(NSString *)title;
 52
 53///-----------------------------------
 54/// @name Adding buttons
 55///-----------------------------------
 56
 57/** Add a new button with an associated code block.
 58
 59 @param title The text of the button.
 60 @param block A block of code.
 61 */
 62- (NSInteger)addButtonWithTitle:(NSString *)title handler:(BKBlock)block;
 63
 64/** Set the destructive (red) button with an associated code block.
 65 
 66 @warning Because buttons cannot be removed from an action sheet,
 67 be aware that the effects of calling this method are cumulative.
 68 Previously added destructive buttons will become normal buttons.
 69
 70 @param title The text of the button.
 71 @param block A block of code.
 72 */
 73- (NSInteger)setDestructiveButtonWithTitle:(NSString *)title handler:(BKBlock)block;
 74
 75/** Set the title and trigger of the cancel button.
 76 
 77 `block` can be set to `nil`, but this is generally useless as
 78 the cancel button is configured already to do nothing.
 79 
 80 iPhone users will have the button shown regardless; if the title is
 81 set to `nil`, it will automatically be localized.
 82 
 83 @param title The text of the button.
 84 @param block A block of code.
 85 */
 86- (NSInteger)setCancelButtonWithTitle:(NSString *)title handler:(BKBlock)block;
 87
 88///-----------------------------------
 89/// @name Altering actions
 90///-----------------------------------
 91
 92/** Sets the block that is to be fired when a button is pressed.
 93 
 94 @param block A code block, or nil to set no response.
 95 @param index The index of a button already added to the action sheet.
 96*/
 97- (void)setHandler:(BKBlock)block forButtonAtIndex:(NSInteger)index;
 98
 99/** The block that is to be fired when a button is pressed.
100 
101 @param index The index of a button already added to the action sheet.
102 @return A code block, or nil if no block is assigned.
103 */
104- (BKBlock)handlerForButtonAtIndex:(NSInteger)index;
105
106/** The block to be fired when the action sheet is dismissed with the cancel
107 button and/or action.
108
109 This property performs the same action as setCancelButtonWithTitle:handler:
110 but with `title` set to nil.  Contrary to setCancelButtonWithTitle:handler:,
111 you can set this property multiple times and multiple cancel buttons will
112 not be generated.
113 */
114@property (nonatomic, copy) BKBlock cancelBlock;
115
116/** The block to be fired before the action sheet will show. */
117@property (nonatomic, copy) void (^willShowBlock)(UIActionSheet *);
118
119/** The block to be fired when the action sheet shows. */
120@property (nonatomic, copy) void (^didShowBlock)(UIActionSheet *);
121
122/** The block to be fired before the action sheet will dismiss. */
123@property (nonatomic, copy) void (^willDismissBlock)(UIActionSheet *, NSInteger);
124
125/** The block to be fired after the action sheet dismisses. */
126@property (nonatomic, copy) void (^didDismissBlock)(UIActionSheet *, NSInteger);
127
128@end