UITableView使用指南
本文转载至 http://blog.csdn.net/yu0089/article/details/8227402
一、概述
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同生同死
style property // 有两种 UITableViewStylePlain, UITableViewStyleGrouped,经常用
– numberOfRowsInSection: //一个section有多少行,经常用
– numberOfSections //一个TableView有多少个section,经常用
rowHeight property // 行高,和tableView:heightForRowAtIndexPath:有性能上的区别
separatorStyle property // cell之间的分割线?待确认
separatorColor property // 同上
backgroundView property // tableview的背景view, 这个背景view在所有cell, header views, footer views之后
tableHeaderView property // tableview上方的一个headerView, 和delete里的section header不是一个概念
tableFooterView property // tableview下方的一个footerview
sectionHeaderHeight property // section Header的高度,
sectionFooterHeight property // sectjion Footer的高度
sectionIndexMinimumDisplayRowCount property // 功能待确认? 参考例子: 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: //反选一行,有何用?
allowsSelection property //是否允许用户选取一行
allowsMultipleSelection property // 是否选取多行,缺省为NO. 可以试试YES后的效果,哈哈
allowsSelectionDuringEditing property // 编辑模式时是否可选取一行
allowsMultipleSelectionDuringEditing property // 编辑模式时可否选取多行
6) 插入、删除、移动行和sections
– beginUpdates // 和endUpdates一起用,让插入、删除、选择操作同时动画,没用过
– endUpdates //
– insertRowsAtIndexPaths:withRowAnimation: //根据indexPath数组插入行
– deleteRowsAtIndexPaths:withRowAnimation: //根据indexPath数组删除行
– moveRowAtIndexPath:toIndexPath: //移动一行到另一行
– insertSections:withRowAnimation: //插入sections
– deleteSections:withRowAnimation: //删除sections
– moveSection:toSection: //移动section
7) 管理和编辑cell
editing property // 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) 管理委托和数据源 (重要)
dataSource property // 通常会这么用: myTableView.delegate = self; self 为viewController
delegate property // 通常会这么用: myTableView.dataSource = self; self 为viewController
原文地址:http://blog.csdn.net/y041039/article/details/7351982
UITableView使用指南的更多相关文章
- uitableview 优化
1. http://www.cocoachina.com/ios/20150602/11968.html 最近在微博上看到一个很好的开源项目VVeboTableViewDemo,是关于如何优化UITa ...
- 环信_EaseUI 使用指南
EaseUI 使用指南 简介 EaseUI 封装了 IM 功能常用的控件(如聊天会话.会话列表.联系人列表).旨在帮助开发者快速集成环信 SDK. 源码地址: EaseUI:https://githu ...
- 李洪强iOS开发之-环信05_EaseUI 使用指南
李洪强iOS开发之-环信05_EaseUI 使用指南 EaseUI 使用指南 简介 EaseUI 封装了 IM 功能常用的控件(如聊天会话.会话列表.联系人列表).旨在帮助开发者快速集成环信 SDK. ...
- Optional变量初学者指南
苹果三周前发布了Swift. 从那时起,我一直在阅读Swift的官方指南,并在Xcode 6测试版中使用. 我开始喜欢Swift的简单和语法. 与我的团队一起,我仍然在研究新的语言,并看看它与Obje ...
- iOS进阶指南试读之UI篇
iOS进阶指南试读之UI篇 UI篇 UI是一个iOS开发工程师的基本功.怎么说?UI本质上就是你调用苹果提供给你的API来完成设计师的设计.所以,想提升UI的功力也很简单,没事就看看UIKit里的各个 ...
- 转:苹果Xcode帮助文档阅读指南
一直想写这么一个东西,长期以来我发现很多初学者的问题在于不掌握学习的方法,所以,Xcode那么好的SDK文档摆在那里,对他们也起不到什么太大的作用.从论坛.微博等等地方看到的初学者提出的问题,也暴露出 ...
- 怎样創建 iOS 展開式 UITableView?
原文:http://www.appcoda.com.tw/expandable-table-view/ 译者:kmyhy(appcoda的驻站译者) 幾乎全部的 App 都會以導航的方式向用戶展示多個 ...
- JavaScript权威指南 - 函数
函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...
- UE4新手之编程指南
虚幻引擎4为程序员提供了两套工具集,可共同使用来加速开发的工作流程. 新的游戏类.Slate和Canvas用户接口元素以及编辑器功能可以使用C++语言来编写,并且在使用Visual Studio 或 ...
随机推荐
- html框架集
通过框架集的使用定义页面分布 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- sublime 中设置pylint
http://www.360doc.com/content/14/1110/11/15077656_424004081.shtml 安装 pylinter 插件 详见 sublime 插件安装 配 ...
- viewpager+fragment出现TransactionTooLargeException的大坑!!!
最近apk包发给部分测试用户,反馈出现很多崩溃,异常是android.os.TransactionTooLargeException,看表面意思就是传送的数据太大,可是检查代码并没有传输很大的数据啊. ...
- [Python Cookbook] Numpy Array Slicing and Indexing
1-D Array Indexing Use bracket notation [ ] to get the value at a specific index. Remember that inde ...
- luogu P1608 路径统计
题目描述 “RP餐厅”的员工素质就是不一般,在齐刷刷的算出同一个电话号码之后,就准备让HZH,TZY去送快餐了,他们将自己居住的城市画了一张地图,已知在他们的地图上,有N个地方,而且他们目前处在标注为 ...
- Oracle 安装前准备
[root@localhost Desktop]# groupadd -g 110 oinstall 用来安装oracle软件 [root@localhost Desktop]# groupadd - ...
- ZFS -世界上最高级的文件系统之一
https://www.oschina.net/news/44302/openzfs_launch_announcement https://en.wikipedia.org/wiki/ZFS ZFS ...
- ios内存管理笔记(一)
- openssl之BIO系列之9---BIO对的创建和应用
BIO对的创建和应用 ---依据openssl doc/crypto/bio/bio_new_bio_pair.pod翻译和自己的理解写成 (作者:DragonKing Mail:wzhah@263. ...
- jquery ajax传参数问题
var fd = new FormData();//实例化表单,提交数据使用fd.append('imgUrl',imgUrl);//将files追加进去fd.append('typeId',type ...