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++ 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二、顺序表数据结构中的顺序表三、常用代码手动

JAVA线程的周期及调度机制详解

《JAVA线程的周期及调度机制详解》Java线程的生命周期包括NEW、RUNNABLE、BLOCKED、WAITING、TIMED_WAITING和TERMINATED,线程调度依赖操作系统,采用抢占... 目录Java线程的生命周期线程状态转换示例代码JAVA线程调度机制优先级设置示例注意事项JAVA线程

详解C++ 存储二进制数据容器的几种方法

《详解C++存储二进制数据容器的几种方法》本文主要介绍了详解C++存储二进制数据容器,包括std::vector、std::array、std::string、std::bitset和std::ve... 目录1.std::vector<uint8_t>(最常用)特点:适用场景:示例:2.std::arra

C++构造函数中explicit详解

《C++构造函数中explicit详解》explicit关键字用于修饰单参数构造函数或可以看作单参数的构造函数,阻止编译器进行隐式类型转换或拷贝初始化,本文就来介绍explicit的使用,感兴趣的可以... 目录1. 什么是explicit2. 隐式转换的问题3.explicit的使用示例基本用法多参数构造

Android使用java实现网络连通性检查详解

《Android使用java实现网络连通性检查详解》这篇文章主要为大家详细介绍了Android使用java实现网络连通性检查的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录NetCheck.Java(可直接拷贝)使用示例(Activity/Fragment 内)权限要求

MyBatis中的两种参数传递类型详解(示例代码)

《MyBatis中的两种参数传递类型详解(示例代码)》文章介绍了MyBatis中传递多个参数的两种方式,使用Map和使用@Param注解或封装POJO,Map方式适用于动态、不固定的参数,但可读性和安... 目录✅ android方式一:使用Map<String, Object>✅ 方式二:使用@Param

JAVA transient 关键字作用详解

《JAVAtransient关键字作用详解》Java的transient关键字用于修饰成员变量,使其不参与序列化过程,通过自定义序列化方法,可以手动控制transient变量的序列化行为,本文给大... 目录一、transient关键字作用二、原理详解三、典型使用场景四、代码示例五、注意事项六、与 stat