代码中回调的用法
//声明回调 typedef void(^discoverCreateBackBlock)(BOOL state); @interface DiscoverCreateViewController //定义回调 @property (nonatomic , copy) discoverCreateBackBlock finishBlock; //发布成功回调Block @property (nonatomic, copy) GetCameraImageBlock getCameraImageBlock; ..... @end
//返回回调 @implementation DiscoverCreateViewController #pragma mark -- #pragma mark -- HTTPRequestDelegate - (void)request:(AFHTTPRequestOperation *)myRequest finshAction:(NSDictionary *)dic withURLTag:(NSString *)url{ int code = [[dic safeObjectForKey:@"status"] intValue]; if (code == 200) { //评论请求成功 if ([url isEqualToString: DISCOVER_ADD_FOUND] ) { ... //[self stopLoadAnimation]; CL_INFO(@"评论请求完成完毕"); if (_arrayPic.count !=0 && self.needExtractPhotosForAnimation) { if (self.finishBlock) { self.finishBlock(YES); } } else{ [self onClickBack]; } } } } @end
//使用回调 DiscoverCreateViewController*recommed = [[DiscoverCreateViewController alloc]init]; recommed.arrayPic = [[NSMutableArray alloc] initWithArray:nil]; recommed.canChooseProduct = NO; recommed.selectedEntity = self.selectedEntity; recommed.isRepost = YES; [recommed setFinishBlock:^(BOOL state){ CL_INFO(@"发布完成,刷新我的关注页面数据"); }]; [self.navigationController pushViewController:recommed animated:YES];