iOS Block小结
1
|
typedefv void (^AdModelRequestComplteHandle)(NSData *); |
1
2
|
void (^completion)(NSTask*) = ^(NSTask *taskComplete){ }; |
1
|
-( void ) requestForADPushCompleteHandle:( void (^) (NSData* )) handler; |
1
2
3
4
5
6
7
8
9
10
|
( void ) handleClickAd:(AdBaseInfo*) adInfo completion:(AdModelHandleClickCompltion) handler { if (!handler) { handler = ^( void ){}; } //或者在使用的时候 if (handler(){ handler(); } } |
1
2
|
//自定义类型,此block返回的类型为void,block名为Completion typedef void (^Completion)(NSString *result1,NSString *result2); |
1
2
3
4
5
6
7
8
|
//事件处理 -( void ) treatment:(Completion) completion { //传入的参数类型为Completion,将处理后的结果回调 NSString *result1 = @ "result1" ; NSString *result2 = @ "result2" ; completion(result1,result2); } |
1
2
3
4
5
|
[self treatment:^(NSString *result1,NSString *result2){ //将block中回调的结果输出 label1.text = result1; label2.text = result2; }]; |
例子地址 :http://pan.baidu.com/share/link?shareid=3719210515&uk=1443516649