[Code note] the button click event on iOS-UITableView,

Source: Internet
Author: User

[Code note] the button click event on iOS-UITableView,

Code.

ViewController. h

#import <UIKit/UIKit.h>@interface ViewController : UIViewController<UITableViewDataSource,UITableViewDelegate>{    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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.