自定义cell上代理添加按钮

2018-06-21  本文已影响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

{

}

上一篇 下一篇

猜你喜欢

热点阅读