- Add Alert block
This commit is contained in:
1 parent
dfd5420089
commit
ab1b14b4e2
43 files changed
+1435
-353
No files matched your search
+7
@@ -0,0 +1,7 @@
|
||||
Copyright (C) 2013 Developed by Shai Mishali
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
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 OR COPYRIGHT HOLDERS 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.
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
UIActionSheet-Blocks
|
||||
================
|
||||
|
||||
UIActionSheet+Blocks is a simple Block implementation for UIActionSheet created by Shai Mishali.
|
||||
This allows you to use the power of blocks instead of implementing a delegate.
|
||||
|
||||
USAGE
|
||||
------
|
||||
|
||||
Instead of allocating a new UIActionSheet and assigning a delegate, just call one of the static methods:
|
||||
|
||||
```objc
|
||||
UIActionSheet *sheet = [UIActionSheet presentOnView:self.view
|
||||
withTitle:@"Select Picture"
|
||||
otherButtons:@[@"Camera Roll", @"Take a Picture"]
|
||||
onCancel:^(UIActionSheet *actionSheet) {
|
||||
NSLog(@"Touched cancel button");
|
||||
}
|
||||
onClickedButton:^(UIActionSheet *actionSheet, NSUInteger index) {
|
||||
NSLog(@"Selected button at index %d", index);
|
||||
}];
|
||||
```
|
||||
|
||||

|
||||
|
||||
**OR**
|
||||
|
||||
```objc
|
||||
|
||||
UIActionSheet *sheet = [UIActionSheet presentOnView:self.view
|
||||
withTitle:@"John - 555-1212"
|
||||
cancelButton:@"Dismiss"
|
||||
destructiveButton:@"Delete Contact"
|
||||
otherButtons:@[@"Call Contact",@"Message Contact"]
|
||||
onCancel:^(UIActionSheet *actionSheet) {
|
||||
NSLog(@"Touched cancel button");
|
||||
}
|
||||
onDestructive:^(UIActionSheet *actionSheet) {
|
||||
NSLog(@"Touched destructive button");
|
||||
}
|
||||
onClickedButton:^(UIActionSheet *actionSheet, NSUInteger index) {
|
||||
NSLog(@"Selected button at index %d", index);
|
||||
}];
|
||||
```
|
||||
|
||||

|
||||
|
||||
|
||||
The class will return the UIActionSheet object which you can manally dismiss if needed.
|
||||
|
||||
LICENSE
|
||||
-------------------
|
||||
|
||||
Copyright (C) 2013 Developed by Shai Mishali
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
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 OR COPYRIGHT HOLDERS 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.
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// UIActionSheet+Blocks.h
|
||||
//
|
||||
// Created by Shai Mishali on 9/26/13.
|
||||
// Copyright (c) 2013 Shai Mishali. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
/**
|
||||
UIActionSheet+Blocks is a simple Block implementation for UIActionSheet created by Shai Mishali.
|
||||
*/
|
||||
|
||||
@interface UIActionSheet (Blocks) <UIActionSheetDelegate>
|
||||
|
||||
/**
|
||||
Present a UIActionSheet on a specific view
|
||||
|
||||
Note: On this shorthand version the cancel button always displayed "Cancel" as the text. If you require a custom cancel text, use the longer method below.
|
||||
|
||||
@param view The view on which the UIActionSheet will be displayed
|
||||
@param title The title of the UIActionSheet
|
||||
@param otherStrings An array containing strings of other buttons
|
||||
@param onCancel Cancel block - Called when the user pressed the cancel button, or the UIActionSheet has been manually dismissed
|
||||
@param onClickedButton Clicked button at index block - Called when the user presses any button other then Cancel
|
||||
|
||||
@return The generated UIActionSheet
|
||||
*/
|
||||
+(UIActionSheet *)presentOnView: (UIView *)view
|
||||
withTitle: (NSString *)title
|
||||
otherButtons: (NSArray *)otherStrings
|
||||
onCancel: (void (^)(UIActionSheet *))cancelBlock
|
||||
onClickedButton: (void (^)(UIActionSheet *, NSUInteger))clickBlock;
|
||||
|
||||
/**
|
||||
Present a UIActionSheet on a specific view
|
||||
|
||||
@param view The view on which the UIActionSheet will be displayed
|
||||
@param title The title of the UIActionSheet
|
||||
@param cancelString The string shown on the Cancel button
|
||||
@param destructiveString The string shown on the Destructive button
|
||||
@param otherStrings An array containing strings of other buttons
|
||||
@param onCancel Cancel block - Called when the user pressed the cancel button, or the UIActionSheet has been manually dismissed
|
||||
@param onDestructive Destructive block - Called when the user presses the destructive button
|
||||
@param onClickedButton Clicked button at index block - Called when the user presses any button other then Cancel/Destructive
|
||||
|
||||
@return The generated UIActionSheet
|
||||
*/
|
||||
+(UIActionSheet *)presentOnView: (UIView *)view
|
||||
withTitle: (NSString *)title
|
||||
cancelButton: (NSString *)cancelString
|
||||
destructiveButton: (NSString *)destructiveString
|
||||
otherButtons: (NSArray *)otherStrings
|
||||
onCancel: (void (^)(UIActionSheet *))cancelBlock
|
||||
onDestructive: (void (^)(UIActionSheet *))destroyBlock
|
||||
onClickedButton: (void (^)(UIActionSheet *, NSUInteger))clickBlock;
|
||||
@end
|
||||
@@ -0,0 +1,77 @@
|
||||
//
|
||||
// UIActionSheet+Blocks.m
|
||||
//
|
||||
// Created by Shai Mishali on 9/26/13.
|
||||
// Copyright (c) 2013 Shai Mishali. All rights reserved.
|
||||
//
|
||||
|
||||
#import "UIActionSheet+Blocks.h"
|
||||
|
||||
static void (^__clickedBlock)(UIActionSheet *sheet, NSUInteger index);
|
||||
static void (^__cancelBlock)(UIActionSheet *sheet);
|
||||
static void (^__destroyBlock)(UIActionSheet *sheet);
|
||||
|
||||
@implementation UIActionSheet (Blocks)
|
||||
|
||||
+(UIActionSheet *)presentOnView:(UIView *)view
|
||||
withTitle:(NSString *)title
|
||||
otherButtons:(NSArray *)otherStrings
|
||||
onCancel:(void (^)(UIActionSheet *))cancelBlock
|
||||
onClickedButton:(void (^)(UIActionSheet *, NSUInteger))clickBlock{
|
||||
|
||||
return [self presentOnView:view
|
||||
withTitle:title
|
||||
cancelButton:NSLocalizedString(@"Cancel", @"")
|
||||
destructiveButton:nil
|
||||
otherButtons:otherStrings
|
||||
onCancel:cancelBlock
|
||||
onDestructive:nil
|
||||
onClickedButton:clickBlock];
|
||||
}
|
||||
|
||||
+(UIActionSheet *)presentOnView: (UIView *)view
|
||||
withTitle: (NSString *)title
|
||||
cancelButton: (NSString *)cancelString
|
||||
destructiveButton: (NSString *)destructiveString
|
||||
otherButtons: (NSArray *)otherStrings
|
||||
onCancel: (void (^)(UIActionSheet *))cancelBlock
|
||||
onDestructive: (void (^)(UIActionSheet *))destroyBlock
|
||||
onClickedButton: (void (^)(UIActionSheet *, NSUInteger))clickBlock{
|
||||
__cancelBlock = cancelBlock;
|
||||
__clickedBlock = clickBlock;
|
||||
__destroyBlock = destroyBlock;
|
||||
|
||||
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:title
|
||||
delegate:(id) [self class]
|
||||
cancelButtonTitle:nil
|
||||
destructiveButtonTitle:destructiveString
|
||||
otherButtonTitles:nil];
|
||||
|
||||
for(NSString *other in otherStrings)
|
||||
[sheet addButtonWithTitle: other];
|
||||
|
||||
if (cancelString) {
|
||||
[sheet setCancelButtonIndex:[sheet addButtonWithTitle:cancelString]];
|
||||
}
|
||||
|
||||
[sheet showInView: view];
|
||||
|
||||
return sheet;
|
||||
}
|
||||
|
||||
#pragma mark - Private Static delegate
|
||||
+(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
|
||||
if([actionSheet destructiveButtonIndex] == buttonIndex && __destroyBlock)
|
||||
__destroyBlock(actionSheet);
|
||||
else if([actionSheet cancelButtonIndex] == buttonIndex && __cancelBlock)
|
||||
__cancelBlock(actionSheet);
|
||||
else if(__clickedBlock)
|
||||
__clickedBlock(actionSheet, buttonIndex);
|
||||
}
|
||||
|
||||
+(void)actionSheetCancel:(UIActionSheet *)actionSheet{
|
||||
if(__cancelBlock)
|
||||
__cancelBlock(actionSheet);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user