美文网首页
自定义cell上代理添加按钮

自定义cell上代理添加按钮

作者: 法库德 | 来源:发表于2018-06-21 17:01 被阅读0次

.h

//声明代理

@protocol HselcellDelegate <NSObject>

//代理方法

-(void)dClickContinueBtn:(UIButton*)button;

@end

@interfaceTwoTableViewCell :UITableViewCell

//自定义的按钮

@property(nonatomic,strong)UIButton *bu;

//

@property (nonatomic, weak) id <HselcellDelegate>delegate;

@end

.m

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier{

    self= [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];

//自定义的按钮

 _bu=[[UIButton alloc]initWithFrame:CGRectMake(HBScreenWidth-140, 24, 150, 20)];

    [_bu setTitle:@"查看更多>" forState:UIControlStateNormal];

    [_bu setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];

    [_bu addTarget:self action:@selector(continueBtnCilke:) forControlEvents:UIControlEventTouchUpInside];

    [self addSubview:_bu];

    return self;

}

//代理的按钮实现

-(void)continueBtnCilke:(UIButton*)sender{

    [self.delegate dClickContinueBtn:sender];

}

Controller.h

遵守协议

<HselcellDelegate>

//在cell中写的

cell2.delegate=self;

#pragma mark - 点击方法

-(void)dClickContinueBtn:(UIButton*)button

{

}

相关文章

网友评论

      本文标题:自定义cell上代理添加按钮

      本文链接:https://www.haomeiwen.com/subject/pbkcyftx.html