zoukankan      html  css  js  c++  java
  • UIAlertView+Blocks.h

    #import <Foundation/Foundation.h>
    
    typedef void (^DismissBlock)(int buttonIndex);
    typedef void (^CancelBlock)();
    
    @interface UIAlertView (Blocks) <UIAlertViewDelegate> 
    
    + (UIAlertView*) showAlertViewWithTitle:(NSString*) title                    
                                    message:(NSString*) message 
                          cancelButtonTitle:(NSString*) cancelButtonTitle
                          otherButtonTitles:(NSArray*) otherButtons
                                  onDismiss:(DismissBlock) dismissed                   
                                   onCancel:(CancelBlock) cancelled;
    
    @end
    //
    //  UIAlertView+Blocks.m
    //  UIKitCategoryAdditions
    //
    
    #import "UIAlertView+Blocks.h"
    
    static DismissBlock _dismissBlock;
    static CancelBlock _cancelBlock;
    
    @implementation UIAlertView (Blocks)
    
    + (UIAlertView*) showAlertViewWithTitle:(NSString*) title                    
                                    message:(NSString*) message 
                          cancelButtonTitle:(NSString*) cancelButtonTitle
                          otherButtonTitles:(NSArray*) otherButtons
                                  onDismiss:(DismissBlock) dismissed                   
                                   onCancel:(CancelBlock) cancelled {
      
      _cancelBlock  = [cancelled copy];
      
      _dismissBlock  = [dismissed copy];
      
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                      message:message
                                                     delegate:[self self]
                                            cancelButtonTitle:cancelButtonTitle
                                            otherButtonTitles:nil];
      
      for(NSString *buttonTitle in otherButtons)
        [alert addButtonWithTitle:buttonTitle];
      
      [alert show];
      return alert;
    }
    
    + (void)alertView:(UIAlertView*) alertView didDismissWithButtonIndex:(NSInteger) buttonIndex {
      
        if(buttonIndex == [alertView cancelButtonIndex])
        {
            _cancelBlock();
        }
      else
      {
        _dismissBlock(buttonIndex - 1); // cancel button is button 0
      }  
    }
    
    
    @end
     
  • 相关阅读:
    071 Simplify Path 简化路径
    070 Climbing Stairs
    069 Sqrt(x) 求平方根
    067 Add Binary 二进制求和
    bzoj3295: [Cqoi2011]动态逆序对
    bzoj1598: [Usaco2008 Mar]牛跑步
    bzoj1492: [NOI2007]货币兑换Cash
    bzoj2683(要改一点代码)&&bzoj1176: [Balkan2007]Mokia
    bzoj2190: [SDOI2008]仪仗队
    bzoj3262: 陌上花开
  • 原文地址:https://www.cnblogs.com/hxwj/p/4796270.html
Copyright © 2011-2022 走看看