tableview delegate 详解

2024-06-18 19:38
文章标签 详解 tableview delegate

本文主要是介绍tableview delegate 详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

#pragma TableViewDelegate

分组

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return self.dataSource.count;

}

每组的行数

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [[self.dataSource objectAtIndex:section]count];

    

}

cell高度

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.section == 0) {

            return 70;

    }

    else

    {

        return 44;

    }

}

cell头的高度

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

{

    if (section == 0)

    {

        return 0;

    }

    else

    {

    return 25;

    }

}

cell脚的高度

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

{

    if (section == 3 ) {

        return 70;

    }

    else

    {

        return 0;

    }

    

}

脚的自定义

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

{

    if (section == 3) {

        UIView * footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 70)];

        

        UIButton *button1=[[UIButton alloc]initWithFrame:CGRectMake(35, 20, tableView.frame.size.width-35*2, 40)];

        

        [button1 setBackgroundImage:[UIImage imageNamed:@"01确定按钮.png"] forState:UIControlStateNormal ];

        [button1 setTitle:@"退出登录" forState:UIControlStateNormal ];

        [button1 addTarget:self action:@selector(quite:) forControlEvents:UIControlEventTouchUpInside ];

        [footView setBackgroundColor:[UIColor clearColor]];

        [footView addSubview:button1];

        return footView ;

    }

    else

    {

        return 0;

    }

    

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    static NSString * identifier = @"identifier3";

    setTableViewCell * cell = (setTableViewCell*)[[tableView dequeueReusableCellWithIdentifier:identifier]lastObject];

    if (cell == nil)

    {

        cell = [[[NSBundle mainBundle]loadNibNamed:@"setTableViewCell" owner:self options:nil]lastObject];

        [cell setSelectionStyle: UITableViewCellSelectionStyleGray];

    }

    if (indexPath.section == 0)

    {

        cell.TX_image.frame = CGRectMake(20, 20, 40, 40);

        cell.MX_label.frame = CGRectMake(70, 30, 200, 30);

        cell.TP_image.frame = CGRectMake(SCREEN_WIDTH-30, 80/2-14/2 ,7, 14);

    }

    else

    {

        cell.TX_image.frame = CGRectMake(20, 20, 20, 20);

        cell.MX_label.frame = CGRectMake(50, 10, 200, 30);

        cell.TP_image.frame = CGRectMake(SCREEN_WIDTH-30, 44/2-14/2, 7, 14);


    }

    NSString * TX = [[[self.dataSource objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]objectForKey:@"TX"];

    cell.TX_image.image = [UIImage imageNamed:TX];

    cell.MX_label.text = [[[self.dataSource objectAtIndex:indexPath.section]objectAtIndex:indexPath.row]objectForKey:@"MC"];

    cell.TP_image.image = [UIImage imageNamed:@"setting_arrow.png"];

   

    

    return cell;


}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    if (indexPath.section == 0)

    {

        NSLog(@"啊哈0");

 

        privateMessageViewController * pM = [[privateMessageViewController alloc]init];


        [self.navigationController pushViewController:pM animated:YES];

        

    }

    else if (indexPath.section == 1)

    {

        if (indexPath.row ==0)

        {

            NSString * str = @"child";

            [self childOrClass:str];

       

        }

        else

        {

            NSString * str = @"class";

            [self childOrClass:str];

        }

    }

    else if (indexPath.section == 2)

    {

        NSLog(@"啊哈2");

        NotFriendlyViewController * notFriendly = [[NotFriendlyViewController alloc]init];

        [self.navigationController pushViewController:notFriendly animated:YES];

    }

    else if (indexPath.section == 3)

    {

        if (indexPath.row == 0) {

            privateSetViewController * privaSet = [[privateSetViewController alloc]init];

            [self.navigationController pushViewController:privaSet animated:YES];

                    }

        else if (indexPath.row == 1)

        {

            FeedBackViewController * feedBack = [[FeedBackViewController alloc]init];

            [self.navigationController pushViewController:feedBack animated:YES];


        }

    }

}

这篇关于tableview delegate 详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1072925

相关文章

基于C++的UDP网络通信系统设计与实现详解

《基于C++的UDP网络通信系统设计与实现详解》在网络编程领域,UDP作为一种无连接的传输层协议,以其高效、低延迟的特性在实时性要求高的应用场景中占据重要地位,下面我们就来看看如何从零开始构建一个完整... 目录前言一、UDP服务器UdpServer.hpp1.1 基本框架设计1.2 初始化函数Init详解

springboot+redis实现订单过期(超时取消)功能的方法详解

《springboot+redis实现订单过期(超时取消)功能的方法详解》在SpringBoot中使用Redis实现订单过期(超时取消)功能,有多种成熟方案,本文为大家整理了几个详细方法,文中的示例代... 目录一、Redis键过期回调方案(推荐)1. 配置Redis监听器2. 监听键过期事件3. Redi

Springboot配置文件相关语法及读取方式详解

《Springboot配置文件相关语法及读取方式详解》本文主要介绍了SpringBoot中的两种配置文件形式,即.properties文件和.yml/.yaml文件,详细讲解了这两种文件的语法和读取方... 目录配置文件的形式语法1、key-value形式2、数组形式读取方式1、通过@value注解2、通过

自定义注解SpringBoot防重复提交AOP方法详解

《自定义注解SpringBoot防重复提交AOP方法详解》该文章描述了一个防止重复提交的流程,通过HttpServletRequest对象获取请求信息,生成唯一标识,使用Redis分布式锁判断请求是否... 目录防重复提交流程引入依赖properties配置自定义注解切面Redis工具类controller

Python容器转换与共有函数举例详解

《Python容器转换与共有函数举例详解》Python容器是Python编程语言中非常基础且重要的概念,它们提供了数据的存储和组织方式,下面:本文主要介绍Python容器转换与共有函数的相关资料,... 目录python容器转换与共有函数详解一、容器类型概览二、容器类型转换1. 基本容器转换2. 高级转换示

HTML5的input标签的`type`属性值详解和代码示例

《HTML5的input标签的`type`属性值详解和代码示例》HTML5的`input`标签提供了多种`type`属性值,用于创建不同类型的输入控件,满足用户输入的多样化需求,从文本输入、密码输入、... 目录一、引言二、文本类输入类型2.1 text2.2 password2.3 textarea(严格

C++ move 的作用详解及陷阱最佳实践

《C++move的作用详解及陷阱最佳实践》文章详细介绍了C++中的`std::move`函数的作用,包括为什么需要它、它的本质、典型使用场景、以及一些常见陷阱和最佳实践,感兴趣的朋友跟随小编一起看... 目录C++ move 的作用详解一、一句话总结二、为什么需要 move?C++98/03 的痛点⚡C++

MySQL中between and的基本用法、范围查询示例详解

《MySQL中betweenand的基本用法、范围查询示例详解》BETWEENAND操作符在MySQL中用于选择在两个值之间的数据,包括边界值,它支持数值和日期类型,示例展示了如何使用BETWEEN... 目录一、between and语法二、使用示例2.1、betwphpeen and数值查询2.2、be

python中的flask_sqlalchemy的使用及示例详解

《python中的flask_sqlalchemy的使用及示例详解》文章主要介绍了在使用SQLAlchemy创建模型实例时,通过元类动态创建实例的方式,并说明了如何在实例化时执行__init__方法,... 目录@orm.reconstructorSQLAlchemy的回滚关联其他模型数据库基本操作将数据添

Java中ArrayList与顺序表示例详解

《Java中ArrayList与顺序表示例详解》顺序表是在计算机内存中以数组的形式保存的线性表,是指用一组地址连续的存储单元依次存储数据元素的线性结构,:本文主要介绍Java中ArrayList与... 目录前言一、Java集合框架核心接口与分类ArrayList二、顺序表数据结构中的顺序表三、常用代码手动