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
     
  • 相关阅读:
    Bzoj 3654 图样图森波 题解
    1.27号考试记录
    博弈论入门小结
    「考试总结」2020-11-18 爆零
    「补题」考试题泛做
    CSP2020 游记,总结与题解
    Luogu2827 「NOIP2016」 蚯蚓
    【学习笔记】四毛子算法
    「考试反思」2020-11-04 临行
    「考试反思」2020-10-31 警示
  • 原文地址:https://www.cnblogs.com/hxwj/p/4796270.html
Copyright © 2011-2022 走看看