• [转]自定义UITableView各种函数


     
    原文地址: http://blog.sina.com.cn/s/blog_7e3132ca0100wyls.html
    在XCode对应头文件中修改该类所继承的父类:
    @interface TableViewController:UIViewController <UITableViewDataSource, UITableViewDelegate>
    {
    }
    在对应的.m文件中添加如下代码:
    @implementation TableViewController
    {
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0,320,460) style:UITableViewStylePlain];
    tableView.dataSource = self;
    tableView.delegate = self;
    [self.view addSubview:tableView];
    }
    这 样就在view上添加了一个tableView,但其样式是默认的,其中的内容也是空白的,而且此时是无法运行的,因为在头文件中添加了 UITableViewDataSource和UITableViewDelegate两个类,所以必须设置一些自定义tableView样式的方法,下 面列举了一些相关的方法:
    设置Cell高度:
    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    设置SectionHeader高度:
    -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    设置SectionFooter高度:
    -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
    设置Section数目:
    -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
     
    设置SectionHeader内容:
    -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    设置各个Section中的Cell个数: 
    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    设置Cell内容: 
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
     
    设置Cell行缩进量:
    -(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
    设置Cell被选中响应前动作(例如:可用以判断选中的Cell,来阻止其响应)
    -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
    设置Cell选中触发响应:
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  • 相关阅读:
    生产者消费者模型
    进程对象及其他方法、僵尸进程与孤儿进程(了解)、互斥锁、进程间通信、IPC机制、生产者消费者模型
    并发编程总结
    京东618一元抢宝系统的架构优化读后感
    阿里游戏高可用架构设计实践 ------读后感
    以《淘宝网》为例,描绘质量属性的六个常见属性场景
    余额宝技术架构及演进-----读后感
    《架构漫谈》---读后感
    心理小程序开发进度七
    心理小程序开发进度九
  • 原文地址:https://www.cnblogs.com/wengzilin/p/2387611.html
Copyright © 2020-2023  润新知