协议用法
来源:互联网 发布:淘宝客新建定向计划 编辑:程序博客网 时间:2024/06/18 03:40
协议就是 让别的类 干一些 自己类干不了的事 , 比如 cell 不能push VC 那么就让VC 去干
2.设置成属性
比如在一个cell 点击button 的时候调用 记得 传一下3个参数 需要几个 自己修改
3.回去 VC 调用 声明 协议
1. 在cell 里面 声明 协议方法 并设置成属性 记得在 interface 上面 所以必须加上 calss
@class DiscoverCellHeadView;@protocol CollectBtnDelgate <NSObject>/** * 收藏点击 代理 * * @param view <#view description#> */-(void)collectBtnClick:(DiscoverCellHeadView *)view WithRquest:(BOOL)request WithResultDescr:(NSString *)resultDescr;@end
2.设置成属性
@interface DiscoverCellHeadView : UIView<DLImageViewDelegate>@property (nonatomic, weak) id <CollectBtnDelgate> delgatecCollectBtn; //代理
比如在一个cell 点击button 的时候调用 记得 传一下3个参数 需要几个 自己修改
if ([self.delgatecCollectBtn conformsToProtocol:@protocol(CollectBtnDelgate)] && [_delgatecCollectBtn respondsToSelector:@selector(collectBtnClick:WithRquest:WithResultDescr:)]) { [self.delgatecCollectBtn collectBtnClick:self WithRquest:YES WithResultDescr:nil]; }
3.回去 VC 调用 声明 协议
@interface DiscoverVC : DLBaseAMTVC <CollectBtnDelgate>
4.设置代理
DiscoverJokeCell *cell = (DiscoverJokeCell *)[tableView dequeueReusableCellWithIdentifier:cellJokeIdentify]; if (!cell) { cell = [[[NSBundle mainBundle] loadNibNamed:@"DiscoverJokeCell" owner:self options:nil] objectAtIndex:0]; } cell.headView.delgatecCollectBtn = self;
5.代理方法
#pragma mark --headView 代理方法-(void)collectBtnClick:(DiscoverCellHeadView *)view WithRquest:(BOOL)request WithResultDescr:(NSString *)resultDescr{ ContentResponseModel *model = [_dataArray objectAtIndex:view.model.info.cellRow]; model.info.isCollect = view.model.info.isCollect; if (request) { if (model.info.isCollect == 1) { [self presentMessageTips:@"添加收藏成功~"]; } else { [self presentMessageTips:@"取消收藏成功~"]; } } else { [self presentMessageTips:resultDescr]; }}
0 0
- 协议用法
- robots协议 用法
- 有关协议的用法
- UDP协议中的用法
- 协议(Protocol)的用法
- zigbee 协议栈睡眠用法
- zigbee 协议栈睡眠用法
- protocol协议的简单用法
- 协议的用法 ios protocol
- IOS 属性 协议 Block用法
- 协议(Protocol)的用法和代码例子
- 协议(Protocol)用法专题总结
- HTTP协议及其request.setAttribute()用法
- WAP开发之SMS协议的用法
- Android 支持网络协议以及简单用法
- 协议(Protocol)的用法和代码例子
- 协议的基本用法和定义
- OC 协议(Protocol)的基本概念和用法
- Android并发编程之全方位解析AsyncTask
- extern 和 extern“C”
- Android_GestureDetector 手势相关
- __BEGIN_DECLS 和__END_DECLS
- HDU2126 二维背包
- 协议用法
- Sybase ASE 15.5 利用自带scripts脚本创建演示数据库pubs2
- ffplay注解
- jQuery ajax方法详解
- 使用 GitHub, Jekyll 打造自己的免费独立博客
- Myeclipse2014中,新建部署Maven项目
- list合并
- 使用BroadcastReceiver进行短信监控
- 跨文档消息传输之postMessage()