Swift - UITableViewCell倒计时重用解决方案

效果

源码

https://github.com/YouXianMing/Swift-Animations

//
// CountDownTimerController.swift
// Swift-Animations
//
// Created by YouXianMing on 16/9/4.
// Copyright © 2016年 YouXianMing. All rights reserved.
// import UIKit class CountDownTimerController: NormalTitleViewController, UITableViewDelegate, UITableViewDataSource { var timesArray : [CellDataAdapter]!
var tableView : UITableView!
var timer : GCDTimer = GCDTimer(inQueue: GCDQueue.mainQueue) override func setup() { super.setup() // Create data source.
timesArray = [CellDataAdapter]() func add(title title : String, countdownTime : Int) { timesArray.append(CountDownTimeCell.Adapter(data: TimeModel(title: title, countdownTime: countdownTime)))
} add(title: "YouXianMing", countdownTime: )
add(title: "Aaron", countdownTime: )
add(title: "Nicholas", countdownTime: )
add(title: "Quentin", countdownTime: )
add(title: "Samirah", countdownTime: )
add(title: "Serafina", countdownTime: )
add(title: "Shanon", countdownTime: )
add(title: "Sophie", countdownTime: )
add(title: "Steven", countdownTime: )
add(title: "Saadiya", countdownTime: ) // Create TableView.
tableView = UITableView(frame: (contentView?.bounds)!)
tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = .None
tableView.rowHeight =
contentView?.addSubview(tableView) // Register cell.
CountDownTimeCell.RegisterTo(tableView) // Timer event.
weak var wself = self
timer.event({ for (_, dataAdapter) in wself!.timesArray.enumerate() { if let model = dataAdapter.data as? TimeModel { model.countDown()
}
} DefaultNotificationCenter.PostMessageTo(NotificationEvent.CountDownTimeCellCountDown.Message()) }, timeIntervalWithSeconds: 1.0)
timer.start()
} func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return timesArray.count
} func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { return tableView.dequeueCellAndLoadContentFromAdapter(timesArray[indexPath.row], indexPath: indexPath)
} func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { (cell as! CustomCell).display = true
} func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) { (cell as! CustomCell).display = false
}
}

Swift - UITableViewCell倒计时重用解决方案的更多相关文章

  1. TableView的cell加载倒计时重用问题解决方案

    TableView的cell加载倒计时重用问题解决方案 效果 说明 1. 写过类似需求的朋友一定知道,TableView上面加载倒计时功能会遇到复杂的重用问题难以解决 2. 本人提供一种解决思路,高效 ...

  2. 【ios开发】UITableViewCell的重用

    移动开发需要解决的一个问题就是资源稀缺的问题.多数情况下是内存问题. 虽然现在的手机都号称大内存,高配置.但是移动app所占用的资源也在跟着不断膨胀, 也是造成内存不足的主要原因. 在前面的例子中,还 ...

  3. ios基础之UITableViewCell的重用(带示例原创)

    之前一个月刚刚系统的开始接触IOS开发,对UI控件大体了解了一遍,但是因为没有实际的参与项目,对细枝末节的还是不很清楚. 昨天突然想到:UITableViewCell的重用到底是怎么回事,上网查了许多 ...

  4. UITableViewCell的重用机制原理

    UITableViewCell的重用机制原理 来自http://blog.csdn.net/omegayy/article/details/7356823 ====================== ...

  5. UITableViewCell在重用ID时为何加上Static关键字

    UITableViewCell在重用ID时为何加上Static关键字 先回顾一下iOS各种变量作用域和生命周期相关知识: 1.方法中临时变量存储在栈区,出了该方法,临时变量会被自动销毁.但是如果给方法 ...

  6. UITableViewCell的重用机制

    UITabelView一般会显示大量数据,如果有多少条数据就新建多少个cell,那么对于内存来说是种极大的负担,这样自然是不合理的,所以才会有重用机制 比如一个家庭办酒席,一共有13桌,每桌20个菜, ...

  7. IOS中UITableViewCell的重用机制原理

    创建UITableViewController子类的实例后,IDE生成的代码中有如下段落: - (UITableViewCell *)tableView:(UITableView *)tableVie ...

  8. swift UITableViewCell 中的单选控制样式

    我昨天在网上找了一晚上的资料,但是大多都是OC得语法,swift资料实在是太少了,使得我这个刚入门swift的彩笔好不吃力,后面一直各种翻阅资料,终于让我找到了 visibleCells 这个方法,直 ...

  9. iOS拍照上传后,在web端显示旋转 Swift+OC版解决方案

    问题描述: 手机头像上传,遇到一个怪现象,就是拍照上传时,手机端显示头像正常,但在web端查看会有一个左旋90度的问题. 并且照片竖怕才会有此问题,横拍不存在. 原因分析: 手机拍照时,用相机拍摄出来 ...

随机推荐

  1. python工具的安装

    下载: python安装包:python-2.7.3.msi pywin32-218.win32-py2.7.exe setuptools安装包:setuptools-0.6c11.win32-py2 ...

  2. AIX网络性能优化简介

    在AIX 中,网络性能的优化可从以下几方面进行: 网络内存(network memory)的调整 socket 缓冲区 (socket buffer) 的调整 网络接口(network interfa ...

  3. Vi Command 【转载】

    原文: http://www.cnblogs.com/Jesenwuzj/archive/2010/03/18/1688776.html Vi中文手册 1.vi的基本概念 基本上vi可以分为三种状态, ...

  4. ubuntu工具积累

    1.sudo apt-get install terminator一款可以切分终端窗口的工具 a.在系统>键盘>快捷键修该ctrl+alt+t快捷应用为terminator,其他的快捷键同 ...

  5. yield学习续:yield return迭代块在Unity3D中的应用——协程

    必读好文推荐: Unity协程(Coroutine)原理深入剖析 Unity协程(Coroutine)原理深入剖析再续 上面的文章说得太透彻,所以这里就记一下自己的学习笔记了. 首先要说明的是,协程并 ...

  6. 20151009 C# 第一篇 基础知识

    20151009 C#:优点: 1. 语法简洁:不直接操作内存,去掉了指针操作 2. 面向对象:具有封装.继承.多态特性 3. 支持Web标准:支持HTML.XML.SOAP 4. 兼容性:遵循.Ne ...

  7. python基础整理笔记(五)

    一. python中正则表达式的一些查漏补缺 1.  给括号里分组的表达式加上别名:以便之后通过groupdict方法来方便地获取. 2.  将之前取名为"name"的分组所获得的 ...

  8. ubuntu 安装pyqt4 eric

    tar xvf eric4-4.5.7.tar.gztar xvf eric4-i18n-zh_CN.GB2312-4.5.7.tar.gzcd eric4-4.5.7/python install. ...

  9. ReactiveCocoa 5.0 初窥:可能是最痛的一次升级

    RAC 5.0 相比于 4.0 有了巨大的变化,不仅是受 swift 3.0 大升级的影响,RAC 对自身项目结构的也进行了大幅度的调整.这个调整就是将 RAC 拆分为四个库:ReactiveCoco ...

  10. Android 5.x特性概览一

    2014年,Google 携 Android 5.X 重装回归.迄今为止已有已有两年有余,全新设计的 UI风格和更加强悍的性能,再一次奠定了Android 的霸主地位.本文将就 UI 方面 Googl ...