自定义cell上代理添加按钮

.h

//声明代理

@protocol HselcellDelegate

//代理方法

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

@end

@interfaceTwoTableViewCell :UITableViewCell

//自定义的按钮

@property(nonatomic,strong)UIButton *bu;

//

@property (nonatomic, weak) id 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

遵守协议

//在cell中写的

cell2.delegate=self;


#pragma mark - 点击方法

-(void)dClickContinueBtn:(UIButton*)button

{

}

你可能感兴趣的:(自定义cell上代理添加按钮)