UITableView使用指南1(呕心原创)
2014-11-12 16:53
211 查看
http://blog.csdn.net/y041039/article/details/7351982
要说UITableView必须要介绍他的几个亲戚:UITableViewDelegate,UITableViewDataSource,UITableViewCell。其中前两个是TableView遵守的两个protocol(别告诉我你不知道啥叫protocol哦)。然后本文会再列出TableView最常用最重要的一些知识点。最后再介绍几个参考例子。
https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
// 代码生成方式,如果你在nib里加的tableview不需要使用这个方法
必须要实现的方法,与TableView同生同死
// 有两种 UITableViewStylePlain, UITableViewStyleGrouped,经常用
//一个section有多少行,经常用
//一个TableView有多少个section,经常用
行高,和
// cell之间的分割线?待确认
// 同上
// tableview的背景view, 这个背景view在所有cell, header views, footer views之后
// tableview上方的一个headerView, 和delete里的section header不是一个概念
// tableview下方的一个footerview
// section Header的高度,
// sectjion Footer的高度
// 功能待确认? 参考例子: TheElements
3)
//是否允许用户选取一行
// 是否选取多行,缺省为NO. 可以试试YES后的效果,哈哈
// 编辑模式时是否可选取一行
// 编辑模式时可否选取多行
// YES进入编辑模式,tableview cell会出现插入、删除、重排序的控件
// 通常会这么用: myTableView.delegate = self; self 为viewController
// 通常会这么用: myTableView.dataSource = self; self 为viewController
要说UITableView必须要介绍他的几个亲戚:UITableViewDelegate,UITableViewDataSource,UITableViewCell。其中前两个是TableView遵守的两个protocol(别告诉我你不知道啥叫protocol哦)。然后本文会再列出TableView最常用最重要的一些知识点。最后再介绍几个参考例子。
https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
// 代码生成方式,如果你在nib里加的tableview不需要使用这个方法
必须要实现的方法,与TableView同生同死
// 有两种 UITableViewStylePlain, UITableViewStyleGrouped,经常用
//一个section有多少行,经常用
//一个TableView有多少个section,经常用
行高,和
// cell之间的分割线?待确认
// 同上
// tableview的背景view, 这个背景view在所有cell, header views, footer views之后
// tableview上方的一个headerView, 和delete里的section header不是一个概念
// tableview下方的一个footerview
// section Header的高度,
// sectjion Footer的高度
// 功能待确认? 参考例子: TheElements
3)
//是否允许用户选取一行
// 是否选取多行,缺省为NO. 可以试试YES后的效果,哈哈
// 编辑模式时是否可选取一行
// 编辑模式时可否选取多行
// YES进入编辑模式,tableview cell会出现插入、删除、重排序的控件
// 通常会这么用: myTableView.delegate = self; self 为viewController
// 通常会这么用: myTableView.dataSource = self; self 为viewController
一、概述
UITableView是iOS开发比不可少也是最重要的一个控件类。可以说任何一个做iOS开发的人都必须熟练使用和掌握它。本文主要就是提供一个学习使用TableView的指南。要说UITableView必须要介绍他的几个亲戚:UITableViewDelegate,UITableViewDataSource,UITableViewCell。其中前两个是TableView遵守的两个protocol(别告诉我你不知道啥叫protocol哦)。然后本文会再列出TableView最常用最重要的一些知识点。最后再介绍几个参考例子。
二、UITableView和它的亲戚们
1. UITableView
参考:https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
1) 初始化 UITableView对象
– initWithFrame:style:
// 代码生成方式,如果你在nib里加的tableview不需要使用这个方法
2)配置TableView
– dequeueReusableCellWithIdentifier://
必须要实现的方法,与TableView同生同死
styleproperty
// 有两种 UITableViewStylePlain, UITableViewStyleGrouped,经常用
– numberOfRowsInSection:
//一个section有多少行,经常用
– numberOfSections
//一个TableView有多少个section,经常用
rowHeightproperty //
行高,和
tableView:heightForRowAtIndexPath:有性能上的区别
separatorStyleproperty
// cell之间的分割线?待确认
separatorColorproperty
// 同上
backgroundViewproperty
// tableview的背景view, 这个背景view在所有cell, header views, footer views之后
tableHeaderViewproperty
// tableview上方的一个headerView, 和delete里的section header不是一个概念
tableFooterViewproperty
// tableview下方的一个footerview
sectionHeaderHeightproperty
// section Header的高度,
sectionFooterHeightproperty
// sectjion Footer的高度
sectionIndexMinimumDisplayRowCountproperty
// 功能待确认? 参考例子: TheElements
3)
访问Cells和Sections
– cellForRowAtIndexPath: //根据IndexPath返回cell
– indexPathForCell: //根据cell返回它的indexPath,和上面的方法互补
– indexPathForRowAtPoint://根据一个几何点返回indexPath,如果超过边界返回nil
– indexPathsForRowsInRect: //根据一个几何的矩形返回矩形所覆盖的行,返回是一个indexPath数组
– visibleCells // 不清楚怎么用,待确认
– indexPathsForVisibleRows //同上
4) 滚动TableView
– scrollToRowAtIndexPath:atScrollPosition:animated: // 滚动到指定位置
– scrollToNearestSelectedRowAtScrollPosition:animated: // 同上
5) 管理sections
– indexPathForSelectedRow //返回选定行的indexPath,单行
– indexPathsForSelectedRows //返回选定行的indexPath数组,多行
– selectRowAtIndexPath:animated:scrollPosition: //根据indexPath选择一行
– deselectRowAtIndexPath:animated: //反选一行,有何用?
allowsSelectionproperty
//是否允许用户选取一行
allowsMultipleSelectionproperty
// 是否选取多行,缺省为NO. 可以试试YES后的效果,哈哈
allowsSelectionDuringEditingproperty
// 编辑模式时是否可选取一行
allowsMultipleSelectionDuringEditingproperty
// 编辑模式时可否选取多行
6) 插入、删除、移动行和sections
– beginUpdates // 和endUpdates一起用,让插入、删除、选择操作同时动画,没用过
– endUpdates //
– insertRowsAtIndexPaths:withRowAnimation: //根据indexPath数组插入行
– deleteRowsAtIndexPaths:withRowAnimation: //根据indexPath数组删除行
– moveRowAtIndexPath:toIndexPath: //移动一行到另一行
– insertSections:withRowAnimation: //插入sections
– deleteSections:withRowAnimation: //删除sections
– moveSection:toSection: //移动section
7) 管理和编辑cell
editingproperty
// YES进入编辑模式,tableview cell会出现插入、删除、重排序的控件
– setEditing:animated: //设置进入退出编辑模式
8) 重新加载TableView
– reloadData // 重建整个表,包括cells、header、footer,indexs
– reloadRowsAtIndexPaths:withRowAnimation: // 改进,不用reload整个表
– reloadSections:withRowAnimation: // 同上
– reloadSectionIndexTitles // 同上
9) 访问TableView的画图区
– rectForSection: // 返回指定section的矩形
– rectForRowAtIndexPath: //返回indexPath指定行的矩形
– rectForFooterInSection: // 返回section的footer矩形
– rectForHeaderInSection: // 返回section的header矩形
10) Registering Nib Objects for Cell Reuse
– registerNib:forCellReuseIdentifier: //
11) 管理委托和数据源 (重要)
dataSourceproperty
// 通常会这么用: myTableView.delegate = self; self 为viewController
delegateproperty
// 通常会这么用: myTableView.dataSource = self; self 为viewController
小结:
一、概述
UITableView是iOS开发比不可少也是最重要的一个控件类。可以说任何一个做iOS开发的人都必须熟练使用和掌握它。本文主要就是提供一个学习使用TableView的指南。要说UITableView必须要介绍他的几个亲戚:UITableViewDelegate,UITableViewDataSource,UITableViewCell。其中前两个是TableView遵守的两个protocol(别告诉我你不知道啥叫protocol哦)。然后本文会再列出TableView最常用最重要的一些知识点。最后再介绍几个参考例子。
二、UITableView和它的亲戚们
1. UITableView
参考:https://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html
1) 初始化 UITableView对象
– initWithFrame:style:
// 代码生成方式,如果你在nib里加的tableview不需要使用这个方法
2)配置TableView
– dequeueReusableCellWithIdentifier://
必须要实现的方法,与TableView同生同死
styleproperty
// 有两种 UITableViewStylePlain, UITableViewStyleGrouped,经常用
– numberOfRowsInSection:
//一个section有多少行,经常用
– numberOfSections
//一个TableView有多少个section,经常用
rowHeightproperty //
行高,和
tableView:heightForRowAtIndexPath:有性能上的区别
separatorStyleproperty
// cell之间的分割线?待确认
separatorColorproperty
// 同上
backgroundViewproperty
// tableview的背景view, 这个背景view在所有cell, header views, footer views之后
tableHeaderViewproperty
// tableview上方的一个headerView, 和delete里的section header不是一个概念
tableFooterViewproperty
// tableview下方的一个footerview
sectionHeaderHeightproperty
// section Header的高度,
sectionFooterHeightproperty
// sectjion Footer的高度
sectionIndexMinimumDisplayRowCountproperty
// 功能待确认? 参考例子: TheElements
3)
访问Cells和Sections
– cellForRowAtIndexPath: //根据IndexPath返回cell
– indexPathForCell: //根据cell返回它的indexPath,和上面的方法互补
– indexPathForRowAtPoint://根据一个几何点返回indexPath,如果超过边界返回nil
– indexPathsForRowsInRect: //根据一个几何的矩形返回矩形所覆盖的行,返回是一个indexPath数组
– visibleCells // 不清楚怎么用,待确认
– indexPathsForVisibleRows //同上
4) 滚动TableView
– scrollToRowAtIndexPath:atScrollPosition:animated: // 滚动到指定位置
– scrollToNearestSelectedRowAtScrollPosition:animated: // 同上
5) 管理sections
– indexPathForSelectedRow //返回选定行的indexPath,单行
– indexPathsForSelectedRows //返回选定行的indexPath数组,多行
– selectRowAtIndexPath:animated:scrollPosition: //根据indexPath选择一行
– deselectRowAtIndexPath:animated: //反选一行,有何用?
allowsSelectionproperty
//是否允许用户选取一行
allowsMultipleSelectionproperty
// 是否选取多行,缺省为NO. 可以试试YES后的效果,哈哈
allowsSelectionDuringEditingproperty
// 编辑模式时是否可选取一行
allowsMultipleSelectionDuringEditingproperty
// 编辑模式时可否选取多行
6) 插入、删除、移动行和sections
– beginUpdates // 和endUpdates一起用,让插入、删除、选择操作同时动画,没用过
– endUpdates //
– insertRowsAtIndexPaths:withRowAnimation: //根据indexPath数组插入行
– deleteRowsAtIndexPaths:withRowAnimation: //根据indexPath数组删除行
– moveRowAtIndexPath:toIndexPath: //移动一行到另一行
– insertSections:withRowAnimation: //插入sections
– deleteSections:withRowAnimation: //删除sections
– moveSection:toSection: //移动section
7) 管理和编辑cell
editingproperty
// YES进入编辑模式,tableview cell会出现插入、删除、重排序的控件
– setEditing:animated: //设置进入退出编辑模式
8) 重新加载TableView
– reloadData // 重建整个表,包括cells、header、footer,indexs
– reloadRowsAtIndexPaths:withRowAnimation: // 改进,不用reload整个表
– reloadSections:withRowAnimation: // 同上
– reloadSectionIndexTitles // 同上
9) 访问TableView的画图区
– rectForSection: // 返回指定section的矩形
– rectForRowAtIndexPath: //返回indexPath指定行的矩形
– rectForFooterInSection: // 返回section的footer矩形
– rectForHeaderInSection: // 返回section的header矩形
10) Registering Nib Objects for Cell Reuse
– registerNib:forCellReuseIdentifier: //
11) 管理委托和数据源 (重要)
dataSourceproperty
// 通常会这么用: myTableView.delegate = self; self 为viewController
delegateproperty
// 通常会这么用: myTableView.dataSource = self; self 为viewController
小结:
相关文章推荐
- UITableView使用指南1(呕心原创)
- UITableView使用指南(呕心原创)
- UITableView使用指南(呕心原创)
- [原创] TopCoder Arena 插件使用指南
- UITableView使用指南1
- 生成包含C库的应用程序----ADS编译器和库文件使用指南 中文翻译(原创)
- [原创]Spring Boot + Mybatis 简易使用指南(一)基础环境搭建
- mybaits及mybaits generator 插件使用指南(亲测原创)
- 最真实Cisco模拟器-dynamips使用指南--本人原创.
- [原创]Spring Boot + Mybatis 简易使用指南(二)多参数方法支持 与 Joda DateTime类型支持
- 便利的开发工具-log4cpp快速使用指南
- ODAC使用指南 (一)ODAC常见问题集 (续一)
- SQLPlus命令使用指南(一)
- GOOGLE使用指南
- Cygwin使用指南
- ODAC使用指南 (一)ODAC常见问题集
- 使用ffmpeg的库编码mpeg的技术(原创)
- SQLPlus命令使用指南(二)
- refactoring tools使用指南
- [原创]在 Visual C++ 中使用内联汇编