当前位置: 移动技术网 > 移动技术>移动开发>IOS > 【代码笔记】iOS-UITableView上的button点击事件

【代码笔记】iOS-UITableView上的button点击事件

2018年02月13日  | 移动技术网移动技术  | 我要评论

【代码笔记】iOS-UITableView上的button点击事件

代码:

ViewController.h

#import 

@interface ViewController : UIViewController

{
    UITableView *myTableView;
    NSArray *dataArr;
}


@end

 

ViewController.m

#import "ViewController.h"
#import "viewTableViewCell.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //UITableView
    [self initTableView];

}
#pragma -mark -functions
-(void)initTableView
{
    
    myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 100, 320, 400)];
    myTableView.backgroundColor=[UIColor whiteColor];
    myTableView.dataSource=self;
    myTableView.delegate=self;
    [self.view addSubview:myTableView];
    
}
#pragma -mark -UITableViewDelegate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 5;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *strID=@"cell";
    viewTableViewCell *cell=(viewTableViewCell *)[tableView dequeueReusableCellWithIdentifier:strID];
    if (nil==cell) {
        cell=[[viewTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:strID];
    }
    [cell.btn addTarget:self action:@selector(doClickButton:) forControlEvents:UIControlEventTouchUpInside];
    
    return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
    
}
#pragma -mark -doClickButton
-(void)doClickButton:(UIButton *)btn
{
    NSLog(@"--doClickButton-----");
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网