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


    代码。

    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
    复制代码
  • 相关阅读:
    scala学习笔记1(表达式)
    TDD实践感悟
    Day 21:Docker 入门教程
    人类创造未来的思想先锋:这些 TED 演示深深震撼着我们
    Android开源项目第二篇——工具库篇
    提交表单
    MVC html.beginform & ajax.beginform
    MVC中的传参并在View中获取
    HTTP 教程
    ID和Name
  • 原文地址:https://www.cnblogs.com/yang-guang-girl/p/7323600.html
Copyright © 2020-2023  润新知