UIActionSheet+Blocks

UIActionSheet+Blocks.h
  
@@ -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
73   UIActionSheet+Blocks.m
  
@@ -0,0 +1,73 @@
   
+//
   
+//  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:cancelString
   
+                                            destructiveButtonTitle:destructiveString
   
+                                                 otherButtonTitles:nil];
   
+    
   
+    for(NSString *other in otherStrings)
   
+        [sheet addButtonWithTitle: other];
   
+    
   
+    [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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值