Swift_TableView(delegate,dataSource,prefetchDataSource 详解)
Swift_TableView(delegate,dataSource,prefetchDataSource 详解)
import UIKit
let identifier = "cellIdentifier"
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UITableViewDataSourcePrefetching {
lazy var tableView: UITableView = {
let tempTableView = UITableView(frame: CGRect(x: 0, y: 20, width: self.view.bounds.size.width, height: self.view.bounds.size.height), style: UITableViewStyle.plain)
tempTableView.delegate = self // 代理
tempTableView.dataSource = self // 数据源
tempTableView.prefetchDataSource = self // 预处理数据源
return tempTableView
}()
lazy var rowArray: Array<Int> = {
let array = [1,2,3,4,5,6,7,8,9]
return array
}()
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(self.tableView)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
/// MARK: UITableViewDataSource
func numberOfSections(in tableView: UITableView) -> Int {
print("numberOfSections:1")
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("numberOfRowsInSection_cell的个数:\(self.rowArray.count)")
return self.rowArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("cellForRowAt_cell:可自定义")
var cell = tableView.dequeueReusableCell(withIdentifier: identifier) // 根据 identifier 从缓冲区取出
if cell == nil {
cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: identifier)
}
cell?.textLabel?.text = "\(self.rowArray[indexPath.row])"
return cell!
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "titleForHeaderInSection"
}
func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return "titleForFooterInSection"
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
print("cell是否可以编辑")
return true
}
func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
print("cell是否可以移动")
return true
}
func sectionIndexTitles(for tableView: UITableView) -> [String]? {
print("右侧索引")
return ["a", "b", "c"]
}
func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int {
print("根据所点击的索引定位到相应的Section")
if title == "a" {
print("点击 a 定位到第一个 section")
return 1
}
return 1
}
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
print("编辑的方式")
return .delete
}
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
print("移动cell后对数据源做相应的处理")
}
/// MARK: UITableViewDataSourcePrefetching
func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) {
print("这个协议方法提供一个数组,这个数组提示了按着本次滑动方向,再接下去要碰到哪些indexPaths了,以UITableView为例,回调过来的这个数组为当前屏幕边缘的indexPath的接下去(上或者下)第10个开始算的indexPath,大概一次5个这样。")
}
func tableView(_ tableView: UITableView, cancelPrefetchingForRowsAt indexPaths: [IndexPath]) {
print("这个协议返回的数组用于在,当我们快速滑动到某个区域后又立刻按着反方向滑动,那么原本被预估要出现的几个indexPath会被取消掉这样,这个数组就是存储被取消预估的indexPath。")
}
/// MARK: UITableViewDelegate
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
print("即将展示cell")
}
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
print("即将展示header")
}
func tableView(_ tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
print("即将展示footer")
}
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
print("已经结束展示cell")
}
func tableView(_ tableView: UITableView, didEndDisplayingHeaderView view: UIView, forSection section: Int) {
print("已经结束展示header")
}
func tableView(_ tableView: UITableView, didEndDisplayingFooterView view: UIView, forSection section: Int) {
print("已经结束展示footer")
}
// func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// //设置cell高度
// }
// func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
// //设置header高度
// }
// func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
// //设置footer高度
// }
// func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
// //预估cell高度 节约时间
// }
// func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
// //预估header高度 节约时间
// }
// func tableView(_ tableView: UITableView, estimatedHeightForFooterInSection section: Int) -> CGFloat {
// //预估footer高度 节约时间
// }
// func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
// //自定义header 视图
// }
// func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
// //自定义footer 视图
// }
// func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
// //扩展的点击效果 用以自定义点击效果
// }
// func tableView(_ tableView: UITableView, shouldHighlightRowAt indexPath: IndexPath) -> Bool {
// //点击cell是否允许高亮
// }
// func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
// //已经高亮
// }
// func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) {
// //解除高亮
// }
// func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? {
// //即将选中cell
// }
// func tableView(_ tableView: UITableView, willDeselectRowAt indexPath: IndexPath) -> IndexPath? {
// //即将结束选中
// }
// func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// //已经选中
// }
// func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
// //已经结束选中
// }
// func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
// //编辑形式
// }
// func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
// //删除的title
// }
// func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
// //编辑动作
// }
// func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
// //编辑内容是否缩进
// }
// func tableView(_ tableView: UITableView, willBeginEditingRowAt indexPath: IndexPath) {
// //即将开始编辑
// }
// func tableView(_ tableView: UITableView, didEndEditingRowAt indexPath: IndexPath?) {
// //已经结束编辑
// }
// func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath {
// //移动cell
// }
// func tableView(_ tableView: UITableView, indentationLevelForRowAt indexPath: IndexPath) -> Int {
// //内容缩进
// }
// func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool {
// //是否展示菜单(复制/粘贴)
// }
// func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
// //是否执行菜单中的动作
// }
// func tableView(_ tableView: UITableView, performAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) {
// //执行菜单中的动作
// }
// func tableView(tableView: UITableView, canFocusRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// //返回能否获得焦点
// }
// func tableView(tableView: UITableView, shouldUpdateFocusInContext context: UITableViewFocusUpdateContext) -> Bool{
// //返回是否将要更新焦点
// }
// func tableView(tableView: UITableView, didUpdateFocusInContext context: UITableViewFocusUpdateContext, withAnimationCoordinator coordinator: UIFocusAnimationCoordinator) {
// //已经更新焦点时调用
// }
// func indexPathForPreferredFocusedViewInTableView(tableView: UITableView) -> NSIndexPath? {
// //返回上一个焦点的indexPath
// }
}
Swift_TableView(delegate,dataSource,prefetchDataSource 详解)的更多相关文章
- Spring的datasource配置详解
一句话,Spring对Hibernate的整合,是在applicationContext.xml中配置sessionFactory来实现的,其中sessionFactory中要装配dataSource ...
- Spring的datasource配置详解【转】
一句话,Spring对Hibernate的整合,是在applicationContext.xml中配置sessionFactory来实现的,其中sessionFactory中要装配dataSource ...
- 反爬虫:利用ASP.NET MVC的Filter和缓存(入坑出坑) C#中缓存的使用 C#操作redis WPF 控件库——可拖动选项卡的TabControl 【Bootstrap系列】详解Bootstrap-table AutoFac event 和delegate的分别 常见的异步方式async 和 await C# Task用法 c#源码的执行过程
反爬虫:利用ASP.NET MVC的Filter和缓存(入坑出坑) 背景介绍: 为了平衡社区成员的贡献和索取,一起帮引入了帮帮币.当用户积分(帮帮点)达到一定数额之后,就会“掉落”一定数量的“帮帮 ...
- XML解析之SAX详解
XML解析之SAX详解 本文属于作者原创 http://www.cnblogs.com/ldnh/ XML解析的五个步骤 1.打开文档 (void)parserDidStartDocument:(NS ...
- IOS中表视图(UITableView)使用详解
IOS中UITableView使用总结 一.初始化方法 - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)styl ...
- (转载)UITableView使用详解
在开发iphone的应用时基本上都要用到UITableView,这里讲解一下UITableView的使用方法及代理的调用情况 UITableView使用详解 - (void)viewDidLoad { ...
- iOS开发——UI篇OC篇&UICollectionView详解+实例
UICollectionView详解+实例 实现步骤: 一.新建两个类 1.继承自UIScrollView的子类,比如HMWaterflowView * 瀑布流显示控件,用来显示所有的瀑布流数据 2. ...
- ios新特征 ARC详解
IOS ARC 分类: IOS ARC2013-01-17 09:16 2069人阅读 评论(0) 收藏 举报 目录(?)[+] 关闭工程的ARC(Automatic Reference Co ...
- tableview 详解I
在开发iphone的应用时基本上都要用到UITableView,这里讲解一下UITableView的使用方法及代理的调用情况 UITableView使用详解 - (void)viewDidLoad { ...
随机推荐
- 使用JS完成注册表单的数据校验
1.前台校验 防君子不防小人 JavaScript被设计用来向HTML页面添加交互行为 JavaScript是一种脚本语言(脚本语言是一种轻量级的编程语言) JavaScript由数行可执行计算机代码 ...
- AGS API for JS代理页的使用
AGS API for JS代理页的使用 1.概述 代理页即使用后端语言编写的请求转发页面,部署在Web应用端.客户端请求先发送到该代理页,代理页再将该请求转发到服务器处理,服务器处理结果再经代理页转 ...
- MySQL数据库备份与还原
备份数据库 1.使用mysqldump命令备份 备份一个数据库:mysqldump -u 用户名 -p密码 数据库名 [表名1,表名2...]>备份文件路径及名字.sql 如 ...
- Hadoop自定义JobTracker和NameNode管理页面
为了可以方便地在hadoop的管理界面(namenode和jobtracker)中自定义展示项,使用代理servlet的方式实现了hadoop的管理界面. 首先, 在org.apache.hadoop ...
- PHP 使用WampServer环境,如何配置虚拟主机域名
很多人不会配置虚拟主机,我这里简单交一下大家,分三步: 1.在 C:\Windows\System32\drivers\etc 文件夹中的文件 Hosts 文件修改代码为: 127.0.0.1 loc ...
- 无需安装 vsftpd , 直接使用 FTP 来管理 docker 容器中的文件
无图无真相,先放个效果图: 背景 使用 docker 来跑一些服务很方便,但是有的时候想管理容器里面的文件却很麻烦 -- 一般常规做法有3种: 通过数据卷或数据卷容器的方式 启动容器的时候时候 ...
- RunDll32.exe 详解及[Windows批处理]清除IE缓存
Rundll32命令详解 文件作用:执行32位DLL文件中的内部函数 位置:X:(当前系统分区)\windows\system32 命令语法: Rundll32.exe DLLname,Functio ...
- Python学习---Python下[字符串]的学习
字符串[不可变] 重点方法: in count() center(50,'*') startswith('h') endwith('h') find('r') : 找不到返回 -1 index('r' ...
- Struts2学习-struts+spring
学习帮助网址:http://www.cnblogs.com/S-E-P/archive/2012/01/18/2325253.html http://blog.csdn.net/ad921012/ar ...
- Yii2用Gii自动生成Module+Model+CRUD
1. 开启gii模块 common/config/main-local.php加入下面代码 return [ 'modules' => [ 'gii' => [ 'class' => ...