.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;
}
//代理的按鈕實(shí)現(xiàn)
-(void)continueBtnCilke:(UIButton*)sender{
? ? [self.delegate dClickContinueBtn:sender];
}
Controller.h
遵守協(xié)議
<HselcellDelegate>
//在cell中寫的
cell2.delegate=self;
#pragma mark - 點(diǎn)擊方法
-(void)dClickContinueBtn:(UIButton*)button
{
}