Tableview快速上手(方法注释到位哦)
来源:互联网 发布:航天科工智慧 java 编辑:程序博客网 时间:2024/06/06 07:26
TableView 是object-c最最最常用的控件了 、来掌握它吧
一)UITableView所在的UIViewController声明两个delegate:UITableViewDelegate和UITableViewDataSource。
二)将UITableView对象的delegate设置成self。
三)根据实际需要实现delegate的具体方法,这里简要介绍一下常用的方法和属性。
1、返回tableview有多少个section
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
2、返回对应的section有多少个元素,也就是每个section对应有多少个cell
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
3、返回指定的row高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
4、返回指定的section的header view的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
5、返回指定的section的footer view的高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
6、 返回指定row的cell,在此函数中用户可以根据自己的需求定义cell的属性和显示风格等(主标题cell.textLabel,副标题cell.detailTextLabel,背景cell.imageView,图标cell.accessoryType等等)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
7、返回指定section的header的titile。
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
8、 返回指定section header的view
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
9、用户选中某cell时的回调函数
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
10、获取某一cell对象
- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath
如果想让cell能响应选中事件,但是选中后的颜色不发生改变的话,设置cell.selectionStyle = UITableViewCellSelectionStyleNone。
如果想删除cell之间的分割线,设置 tableview.separatorStyle = UITableViewCellSeparatorStyleNone。
0 0
- Tableview快速上手(方法注释到位哦)
- java连接池一例(注释非常详细到位)
- AndroidStudio快速注释方法
- 快速上手Spring--9. Lookup方法注入
- 快速上手Spring--9. Lookup方法注入
- 快速上手Spring--9. Lookup方法注入
- 快速上手Spring--9. Lookup方法注入
- 快速上手Spring--9.Lookup方法注入
- Python快速上手(一)
- Python快速上手(二)
- Python快速上手(三)
- python3 快速上手(总结)
- Django 快速上手(一)
- 快速上手
- SVN快速上手(一)安装
- (原创)单元测试Junit快速上手
- Enterprise Library 4.1 快速上手(图)
- Enterprise Library 4.1 快速上手(图)
- C++整理——const指针
- cygwin解决tar.gz包乱码问题
- ReactNative添加删除包
- mfc扩展dll 的调用以及dll中creat出错分析
- SSL 1608 皇宫看守 树形dp
- Tableview快速上手(方法注释到位哦)
- 1.Java之HelloWorld
- CAS单点登录学习笔记
- TCP/IP详解学习笔记(10)-TCP连接的建立与中止
- Windows下配置nginx+php(wnmp)
- 9个循环2
- 开心就好
- Java高级之Exchanger
- 易点固定资产管理云平台: “互联网+”下的固定资产管理设想