Skip to content
Browse files

Added code for action sheet

  • Loading branch information...
1 parent f8474c7 commit 69379e9740eb5911448ac0df2879872b8f7498c2 @MugunthKumar committed Mar 22, 2011
Showing with 62 additions and 27 deletions.
  1. +12 −12 UIActionSheet+MKBlockAdditions.h
  2. +50 −15 UIActionSheet+MKBlockAdditions.m
View
24 UIActionSheet+MKBlockAdditions.h
@@ -9,7 +9,7 @@
#import <UIKit/UIKit.h>
#import "MKBlockAdditions.h"
-@interface UIActionSheet (MKBlockAdditions) <UIAlertViewDelegate> {
+@interface UIActionSheet (MKBlockAdditions) <UIActionSheetDelegate> {
}
@@ -21,18 +21,18 @@
onCancel:(CancelBlock) cancelled;
-+ (void) alertViewWithTitle:(NSString*) title
- message:(NSString*) message
- destructiveButtonTitle:(NSString*) descructiveButtonTitle
- buttons:(NSArray*) buttonTitles
- showInView:(UIView*) view
- onDismiss:(DismissBlock) dismissed
- onCancel:(CancelBlock) cancelled;
++ (void) actionSheetWithTitle:(NSString*) title
+ message:(NSString*) message
+ destructiveButtonTitle:(NSString*) destructiveButtonTitle
+ buttons:(NSArray*) buttonTitles
+ showInView:(UIView*) view
+ onDismiss:(DismissBlock) dismissed
+ onCancel:(CancelBlock) cancelled;
-+ (void) photoPickerAlertViewWithTitle:(NSString*) title
- showInView:(UIView*) view
- onDismiss:(DismissBlock) dismissed
- onCancel:(CancelBlock) cancelled;
++ (void) photoPickerWithTitle:(NSString*) title
+ showInView:(UIView*) view
+ onDismiss:(DismissBlock) dismissed
+ onCancel:(CancelBlock) cancelled;
@end
View
65 UIActionSheet+MKBlockAdditions.m
@@ -8,6 +8,8 @@
#import "UIActionSheet+MKBlockAdditions.h"
+static DismissBlock _dismissBlock;
+static CancelBlock _cancelBlock;
@implementation UIActionSheet (MKBlockAdditions)
@@ -18,29 +20,62 @@ +(void) actionSheetWithTitle:(NSString*) title
showInView:(UIView*) view
onDismiss:(DismissBlock) dismissed
onCancel:(CancelBlock) cancelled
-{
-
+{
}
-
-+ (void) alertViewWithTitle:(NSString*) title
- message:(NSString*) message
- destructiveButtonTitle:(NSString*) descructiveButtonTitle
- buttons:(NSArray*) buttonTitles
- showInView:(UIView*) view
- onDismiss:(DismissBlock) dismissed
- onCancel:(CancelBlock) cancelled
++ (void) actionSheetWithTitle:(NSString*) title
+ message:(NSString*) message
+ destructiveButtonTitle:(NSString*) destructiveButtonTitle
+ buttons:(NSArray*) buttonTitles
+ showInView:(UIView*) view
+ onDismiss:(DismissBlock) dismissed
+ onCancel:(CancelBlock) cancelled
{
+ [_cancelBlock release];
+ _cancelBlock = [cancelled copy];
-}
+ [_dismissBlock release];
+ _dismissBlock = [dismissed copy];
+ UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:title
+ delegate:[self class]
+ cancelButtonTitle:NSLocalizedString(@"Cancel", @"")
+ destructiveButtonTitle:destructiveButtonTitle
+ otherButtonTitles:nil];
+
+ for(NSString* thisButtonTitle in buttonTitles)
+ [actionSheet addButtonWithTitle:thisButtonTitle];
+
+ if([view isKindOfClass:[UIView class]])
+ [actionSheet showInView:view];
+
+ if([view isKindOfClass:[UITabBar class]])
+ [actionSheet showFromTabBar:(UITabBar*) view];
+
+ if([view isKindOfClass:[UIBarButtonItem class]])
+ [actionSheet showFromBarButtonItem:(UIBarButtonItem*) view animated:YES];
+
+ [actionSheet release];
+
+}
-+ (void) photoPickerAlertViewWithTitle:(NSString*) title
- showInView:(UIView*) view
- onDismiss:(DismissBlock) dismissed
- onCancel:(CancelBlock) cancelled
++ (void) photoPickerWithTitle:(NSString*) title
+ showInView:(UIView*) view
+ onDismiss:(DismissBlock) dismissed
+ onCancel:(CancelBlock) cancelled
{
}
+-(void)actionSheet:(UIActionSheet*) actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex
+{
+ if(buttonIndex == [actionSheet cancelButtonIndex])
+ {
+ _cancelBlock();
+ }
+ else
+ {
+ _dismissBlock(buttonIndex);
+ }
+}
@end

0 comments on commit 69379e9

Please sign in to comment.
Something went wrong with that request. Please try again.