zoukankan      html  css  js  c++  java
  • UITableview xib里面 cell 按钮的回调

    //  MoreBtnCell.m
    #import
    <UIKit/UIKit.h> @interface MoreBtnCell : UITableViewCell @property (weak, nonatomic) IBOutlet UIButton *BtnOnee; @property (weak, nonatomic) IBOutlet UIButton *BtnTwoo; @property (copy, nonatomic) void(^btnOne_block)(void); @property (copy, nonatomic) void(^btnTwo_block)(void); - (IBAction)BtnOneClicked:(id)sender; - (IBAction)BtnTwoClicked:(id)sender;
    #import "MoreBtnCell.h"
    
    @implementation MoreBtnCell
    
    - (void)awakeFromNib {
        // Initialization code
    }
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
        [super setSelected:selected animated:animated];
    
        // Configure the view for the selected state
    }
    
    - (IBAction)BtnOneClicked:(id)sender {
        _btnOne_block ? _btnOne_block() : nil;
    }
    
    - (IBAction)BtnTwoClicked:(id)sender {
        _btnTwo_block ? _btnTwo_block() : nil;
    }
    @end

    VC cell里面点击按钮

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString * ide = @"lan";
        MoreBtnCell * cell = [tableView dequeueReusableCellWithIdentifier:ide forIndexPath:indexPath];
        __weak MoreBtnCell * weak_cell = cell;
        cell.btnOne_block = ^(){
    //        这里回调 ,indexpath可以直接获取,btn也可以直接获取,如果有需要,还可以给btn加tag值,随意了
            [weak_cell.BtnOnee setTitle:@"回调了" forState:UIControlStateNormal];
            ViewController *view=[[ViewController alloc]init];
            [self.navigationController pushViewController:view animated:YES];
    
        };
        cell.btnTwo_block = ^(){
    //        这里回调
            [weak_cell.BtnTwoo setTitle:@"回调" forState:UIControlStateNormal];
        };
        return cell;
    }

    效果图:

  • 相关阅读:
    CGLib实现不同类中同名不同类型属性复制
    stream 伪复用实现
    年终盘点 | 2020年,国内私有云正式进入3.0时代
    高危端口135,137,138,139,445,1025,2475,3127,6129,3389,593
    在jsp引入js失败,提示404
    安全漏洞扫描
    Go 实现的文件行数统计工具
    .NET Core 获取域名 DNS 解析记录
    .NET Core 操作 Windows 注册表
    .NET MongoDb BsonDocument 序列化
  • 原文地址:https://www.cnblogs.com/sayimba/p/5662888.html
Copyright © 2011-2022 走看看