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

相关文章

python中列表应用和扩展性实用详解

《python中列表应用和扩展性实用详解》文章介绍了Python列表的核心特性:有序数据集合,用[]定义,元素类型可不同,支持迭代、循环、切片,可执行增删改查、排序、推导式及嵌套操作,是常用的数据处理... 目录1、列表定义2、格式3、列表是可迭代对象4、列表的常见操作总结1、列表定义是处理一组有序项目的

python使用try函数详解

《python使用try函数详解》Pythontry语句用于异常处理,支持捕获特定/多种异常、else/final子句确保资源释放,结合with语句自动清理,可自定义异常及嵌套结构,灵活应对错误场景... 目录try 函数的基本语法捕获特定异常捕获多个异常使用 else 子句使用 finally 子句捕获所

C++11范围for初始化列表auto decltype详解

《C++11范围for初始化列表autodecltype详解》C++11引入auto类型推导、decltype类型推断、统一列表初始化、范围for循环及智能指针,提升代码简洁性、类型安全与资源管理效... 目录C++11新特性1. 自动类型推导auto1.1 基本语法2. decltype3. 列表初始化3

SQL Server 中的 WITH (NOLOCK) 示例详解

《SQLServer中的WITH(NOLOCK)示例详解》SQLServer中的WITH(NOLOCK)是一种表提示,等同于READUNCOMMITTED隔离级别,允许查询在不获取共享锁的情... 目录SQL Server 中的 WITH (NOLOCK) 详解一、WITH (NOLOCK) 的本质二、工作

springboot自定义注解RateLimiter限流注解技术文档详解

《springboot自定义注解RateLimiter限流注解技术文档详解》文章介绍了限流技术的概念、作用及实现方式,通过SpringAOP拦截方法、缓存存储计数器,结合注解、枚举、异常类等核心组件,... 目录什么是限流系统架构核心组件详解1. 限流注解 (@RateLimiter)2. 限流类型枚举 (

Java Thread中join方法使用举例详解

《JavaThread中join方法使用举例详解》JavaThread中join()方法主要是让调用改方法的thread完成run方法里面的东西后,在执行join()方法后面的代码,这篇文章主要介绍... 目录前言1.join()方法的定义和作用2.join()方法的三个重载版本3.join()方法的工作原

Spring AI使用tool Calling和MCP的示例详解

《SpringAI使用toolCalling和MCP的示例详解》SpringAI1.0.0.M6引入ToolCalling与MCP协议,提升AI与工具交互的扩展性与标准化,支持信息检索、行动执行等... 目录深入探索 Spring AI聊天接口示例Function CallingMCPSTDIOSSE结束语

C语言进阶(预处理命令详解)

《C语言进阶(预处理命令详解)》文章讲解了宏定义规范、头文件包含方式及条件编译应用,强调带参宏需加括号避免计算错误,头文件应声明函数原型以便主函数调用,条件编译通过宏定义控制代码编译,适用于测试与模块... 目录1.宏定义1.1不带参宏1.2带参宏2.头文件的包含2.1头文件中的内容2.2工程结构3.条件编

PyTorch中的词嵌入层(nn.Embedding)详解与实战应用示例

《PyTorch中的词嵌入层(nn.Embedding)详解与实战应用示例》词嵌入解决NLP维度灾难,捕捉语义关系,PyTorch的nn.Embedding模块提供灵活实现,支持参数配置、预训练及变长... 目录一、词嵌入(Word Embedding)简介为什么需要词嵌入?二、PyTorch中的nn.Em

Python Web框架Flask、Streamlit、FastAPI示例详解

《PythonWeb框架Flask、Streamlit、FastAPI示例详解》本文对比分析了Flask、Streamlit和FastAPI三大PythonWeb框架:Flask轻量灵活适合传统应用... 目录概述Flask详解Flask简介安装和基础配置核心概念路由和视图模板系统数据库集成实际示例Stre