协议用法

协议就是 让别的类 干一些  自己类干不了的事 , 比如 cell  不能push VC 那么就让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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值