自定义UITableViewCell上添加UIButton按钮实现选中的是哪个按钮对应的cell,用代理实现。
1.第一步,再自定义cell的.h文件中,声明一个协议;
#import <UIKit/UIKit.h>
//创建一个代理,用于点击按钮的时候将当前cell传到控制器中,
@protocol myTabVdelegate <NSObject>
-(void)myTabVClick:(UITableViewCell *)cell;
@end
@interface CustomTableViewCell : UITableViewCell
//声明一个代理属性
@property(assign,nonatomic)id<myTabVdelegate>delegate;
@property(strong,nonatomic)UIButton *btn;
@end
2.在自定义cell的.m文件中,添加一个uibutton按钮,并实现点击事件中调用代理方法
//按钮点击触发事件
-(void)testAction:(UIButton *)sender