李洪强iOS开发之 - block的使用
李洪强iOS开发之 - block的使用
01 - 定义block
//支付block
typedef void(^invokePayBlock)(CFBaseOrderModel *model);
02 - 根据定义的block声明block属性
@property (copy, nonatomic) invokePayBlock payBlock;
03 - 在.h 和.m中给按钮脱线
![](https://images2015.cnblogs.com/blog/963142/201609/963142-20160922091917762-1719952714.png)
-(IBAction)invokePayBlockHandler:(id)sender;
-(IBAction)invokeDelOrderBlockHandler:(id)sender;
-(IBAction)invokeReceiptBlockHandler:(id)sender;
-(IBAction)invokeRepurchaseBlockHandler:(id)sender;
-(IBAction)invokeRevaluateBlockHandler:(id)sender;
04 - 在.m文件中给block赋值
![](https://images2015.cnblogs.com/blog/963142/201609/963142-20160922091937199-1705748248.png)
-(IBAction)invokePayBlockHandler:(id)sender
{
self.payBlock(tmpModel);
}
05 - 来到控制器中调用原来定义号的block,并且在block中调用
按钮所要实现的功能的方法
![](https://images2015.cnblogs.com/blog/963142/201609/963142-20160922092023762-1513114026.png)
![](https://images2015.cnblogs.com/blog/963142/201609/963142-20160922092000137-1325402953.png)
footerView.payBlock = ^(CFBaseOrderModel *model)
{
[weakSelf callbackPayHandler:section_];
};
06 - block中调用的方法