Block实现简单的代理

简单说一个Block,Block是ios4.0以后推出的一个C级别的语法,自此以后许多方法都有用Block封装,这里有必要介绍一下Block实现简单的代理回调

代理文件.h文件
#import <UIKit/UIKit.h>

@interface CustomAlertView : UIView
{
    
    void (^buttonClickBlock) (CustomAlertView *);
    
    
}

@property (nonatomic,copy) void (^buttonClickBlock) (CustomAlertView *);

@end
.m文件
- (void)buttonClick
{  
   //这里注意传递的参数要跟前面的保持一致
    buttonClickBlock(self);
}
代理实现文件.m
{

CustomAlertView *alertView = [[CustomAlertView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)];
    alertView.buttonClickBlock = ^(CustomAlertView *alertView)
    {   //这里可以接收alertView
        self.view.backgroundColor = [UIColor blueColor];
       
    };


}
原文地址:https://www.cnblogs.com/leeAsia/p/3249527.html