Skip to content

为UIAlertView动态添加一个Block属性,将AlertView与button的点击操作关联,简单的区分处理一个视图有多个AlertView弹窗

Notifications You must be signed in to change notification settings

jaybinhe/JBAlertView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

JBAlertView(UIAlertView+JBAlertView)

Overview

JBAlertView为UIAlertView动态添加一个Block属性,将AlertView与button的点击操作关联,简单的区分处理一个视图有多个AlertView弹窗

github

Usage

初始化AlertView,设置Block

#import "UIAlertView+JBAlertView.h"


//初始化AlertView1
UIAlertView *alertView1 = [[UIAlertView alloc] initWithTitle:@"alertView1" message:nil delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
    alertView1.alertViewBlock = ^(NSInteger index){

    if(1==index){
        NSLog(@"click OK_button");
    }
    else if (0==index){
        NSLog(@"click Cancel_button");
    }

    };

[alertView1 show];


//初始化AlertView2
UIAlertView *alertView2 = [[UIAlertView alloc] initWithTitle:@"alertView2" message:nil delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"ok", nil];
    alertView2.alertViewBlock = ^(NSInteger index){

    if(1==index){
        NSLog(@"click OK_button");
    }
    else if (0==index){
        NSLog(@"click Cancel_button");
    }

};

[alertView2 show];

实现UIAlertViewDelegate方法

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    alertView.alertViewBlock(buttonIndex);
}

About

为UIAlertView动态添加一个Block属性,将AlertView与button的点击操作关联,简单的区分处理一个视图有多个AlertView弹窗

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published