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;
}

效果图:

时间: 2024-08-06 10:29:35

UITableview xib里面 cell 按钮的回调的相关文章

iOS深入学习(UITableView系列4:使用xib自定义cell)

可以通过继承UITableViewCell重新自定义cell,可以像下面一样通过代码来自定义cell,但是手写代码总是很浪费时间, ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 //CustomTableViewCell.h文件 @interface CustomTableViewCell:UITableViewCell @property (nonat

【UIKit】UITableView.09 自定义cell

UITableView.09 自定义cell : 注意:在创建一个故事版的时候,需要将控制器的class修改成对应的class否则效果实现不了[如图] 1.这段代码就是用来设置cell所对应的xib,类似于绑定  // 1.想要使用文件包里面的资源就要使用[NSBundle mainBundle] // 2.loadNibNamed的意思是加载一个xib文件,名字为BookCell cell=[[[NSBundle mainBundle]loadNibNamed:@"BookCell"

IOS xib在tableview上的简单应用(通过xib自定义cell)

UITableView是一种常用的UI控件,在实际开发中,由于原生api的局限,自定义UITableViewCell十分重要,自定义cell可以通过代码,也可以通过xib. 这篇随笔介绍的是通过xib自定义cell. 首先通过gif介绍如何创建xib. 然后实现代码部分,要注意的是实现代码的同时要使代码与xib相关联.-如图 下面便是代码,一些解释我在代码中注释了. ViewController.m // // ViewController.m // CX-Xib在tableView中的简单应用

2015 IOS tabelView分组、Xib、Cell——在蓝懿教育 学习笔记

TabelView分组.表头,表尾 删除vc 搭建tvc 分组界面中return 2 分2组: 在控制行加判断 如果section== 1  return10 (此时012 0123456789) 在sb中选中tv在style右样式改成Grouped 此时有了间隔 控制分组题头和尾.有个字符串 -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{ return @"我

开发进阶18_通过xib自定义Cell

UITableViewController 继承自ViewController,TableViewController自动给我们添加了dataSource和delegate. 里面只有一个UITableView 1.UITableViewController内部默认会创建一个UITableView *tableView 2.UITableViewController内部tableView的delegate和dataSource就是这个UITableViewController 3.UITable

Swift_ uitableview使用自定义cell

uitableview 使用 xib 的自定义cell 新建cell:(假如命名 MyCell) 使用: 向 tableview 注册 nib 全局变量 let cellIdentifier = "myCell" myTableView!.registerNib(UINib(nibName: "MyCell", bundle:nil), forCellReuseIdentifier: cellIdentifier) 然后在 cellForRowAtIndexPath

转--动态改变UITableView中的Cell高度

往往在开发iPhone的应用过程中用得最多的应该算是UITableVIew了,凭着IOS给UITableView赋予了这种灵活的框架结构,让它不管在显示列表方面还是在排版方面都有着一定的优势.虽然UITableView功能强大,但是对于一些复杂的应用需求在开发的过程中会出现一些问题,如动态改变UITableView显示的Cell高度就是其中之一 其实想要改变UITableView的Cell高度并不难,UITableView带有一个rowHeight属性,使用他就可以改变高度了.但是这样的改变是把

一个最简单的cell按钮点击回调

在cell.h定义 @property(nonatomic,strong)void(^pushType)(NSInteger); 在cell.m按钮点击时  _pushType(1):(举例) 在用到cell的tableView中 cell.pushType=^(NSInteger index){ if(index==1){ ... } };

猫猫学IOS(十六)UI之XIB自定义Cell实现团购UI

猫猫分享,必须精品 素材代码地址:http://blog.csdn.net/u013357243/article/details/44926809 原文地址:http://blog.csdn.net/u013357243?viewmode=contents 先看效果图 自定义Cell 本次主要是自定义Cell的学习 实现自定义Cell主要有三种方法:按照使用的频繁度排序: XIB > 纯代码 > StoryBoard XIB的定义步骤 1> 新建HMTgCell.xib 2> 拽一