针对tableview中button的解决方法
在自定义tableviewcell中声明协议
//声明协议
@protocol HJMAddCellDelegate <NSObject>
- (void)xiangqingButton:(UIButton *)sender;
- (void)xinzengButtton:(UIButton *)sender;
@end
@interface HJMAddCell : UITableViewCell
// 声明代理
@property (nonatomic,weak)id <HJMAddCellDelegate>delegate;
在.m文件中需要实现
// 详情
self.detailsButton = [[UIButton alloc]init];
[self.detailsButton addTarget:self action:@selector(detailsClick:) forControlEvents:UIControlEventTouchUpInside] ;
self.addButon = [[UIButton alloc]init];
[self.addButon addTarget:self action:@selector(addButonClick:) forControlEvents:UIControlEventTouchUpInside ];
重点在这 实现按钮方法
- (void)detailsClick:(UIButton *)button
{
[self.delegate xiangqingButton:button];
}
- (void)addButonClick:(UIButton *)button
{
[self.delegate xinzengButtton:button];
}
需要在控制器中实现代理方法遵守协议
@interface HJMAddController ()<UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate, HJMAddCellDelegate>
// 实现代理方法
- (void)xinzengButtton:(UIButton *)sender{
NSArray *array1 = (NSArray *)sender.superview.subviews;
// NSLog(@"434343434343434343%@", array1);
UIButton *button = array1[array1.count - 2];
if ([button.currentTitle isEqual:@"回访"]){
UIView *v = [sender superview];
UIView *v1 = [v superview];
UITableViewCell *cell1 = (UITableViewCell *)[v1 superview];
NSIndexPath *index = [self.tableview indexPathForCell:cell1];
HJMAddModel *model = self.dataArray[(long)index.row];
HJMHuiFangController *huifang = [[HJMHuiFangController alloc]init];
huifang.addModel = model;
huifang.userCode = self.userCode;
huifang.identity = self.identity;
huifang.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:huifang animated:YES];
}
}
上面就是解决tableviewcell中含有点击按钮的问题