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

时间:2023-03-10 00:45:52
【代码笔记】iOS-UITableView上的button点击事件

代码。

ViewController.h

【代码笔记】iOS-UITableView上的button点击事件
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
<UITableViewDataSource,UITableViewDelegate>
{
UITableView *myTableView;
NSArray *dataArr;
} @end
【代码笔记】iOS-UITableView上的button点击事件

ViewController.m

【代码笔记】iOS-UITableView上的button点击事件
#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
【代码笔记】iOS-UITableView上的button点击事件