UITableView中button

这里写图片描述
针对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中含有点击按钮的问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值