Swift - UITableViewCell倒计时重用解决方案
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倒计时重用解决方案的更多相关文章
- TableView的cell加载倒计时重用问题解决方案
TableView的cell加载倒计时重用问题解决方案 效果 说明 1. 写过类似需求的朋友一定知道,TableView上面加载倒计时功能会遇到复杂的重用问题难以解决 2. 本人提供一种解决思路,高效 ...
- 【ios开发】UITableViewCell的重用
移动开发需要解决的一个问题就是资源稀缺的问题.多数情况下是内存问题. 虽然现在的手机都号称大内存,高配置.但是移动app所占用的资源也在跟着不断膨胀, 也是造成内存不足的主要原因. 在前面的例子中,还 ...
- ios基础之UITableViewCell的重用(带示例原创)
之前一个月刚刚系统的开始接触IOS开发,对UI控件大体了解了一遍,但是因为没有实际的参与项目,对细枝末节的还是不很清楚. 昨天突然想到:UITableViewCell的重用到底是怎么回事,上网查了许多 ...
- UITableViewCell的重用机制原理
UITableViewCell的重用机制原理 来自http://blog.csdn.net/omegayy/article/details/7356823 ====================== ...
- UITableViewCell在重用ID时为何加上Static关键字
UITableViewCell在重用ID时为何加上Static关键字 先回顾一下iOS各种变量作用域和生命周期相关知识: 1.方法中临时变量存储在栈区,出了该方法,临时变量会被自动销毁.但是如果给方法 ...
- UITableViewCell的重用机制
UITabelView一般会显示大量数据,如果有多少条数据就新建多少个cell,那么对于内存来说是种极大的负担,这样自然是不合理的,所以才会有重用机制 比如一个家庭办酒席,一共有13桌,每桌20个菜, ...
- IOS中UITableViewCell的重用机制原理
创建UITableViewController子类的实例后,IDE生成的代码中有如下段落: - (UITableViewCell *)tableView:(UITableView *)tableVie ...
- swift UITableViewCell 中的单选控制样式
我昨天在网上找了一晚上的资料,但是大多都是OC得语法,swift资料实在是太少了,使得我这个刚入门swift的彩笔好不吃力,后面一直各种翻阅资料,终于让我找到了 visibleCells 这个方法,直 ...
- iOS拍照上传后,在web端显示旋转 Swift+OC版解决方案
问题描述: 手机头像上传,遇到一个怪现象,就是拍照上传时,手机端显示头像正常,但在web端查看会有一个左旋90度的问题. 并且照片竖怕才会有此问题,横拍不存在. 原因分析: 手机拍照时,用相机拍摄出来 ...
随机推荐
- How to Use JUnit With JMeter
Do you need to use JUnit in your testing processes? To answer this question, let's take a look first ...
- java JVM垃圾回收机制
Java语言出来之前,大家都在拼命的写C或者C++的程序,而此时存在一个很大的矛盾,C++等语言创建对象要不断的去开辟空间,不用的时候有需要不断的去释放控件,既要写构造函数,又要写析构函数,很多时候都 ...
- freeCodeCamp:Title Case a Sentence
确保字符串的每个单词首字母都大写,其余部分小写. 像'the'和'of'这样的连接符同理. /*思路 将字符串转为小写.toLowerCase() 分割字符串以单词形式组成数组myarr 确保数组中的 ...
- Android入门
在学Android,摘自<第一行代码——Android> 布局管理 通过xml文件进行布局管理. android:id="@+id/button_1" 为当前的元素定义 ...
- js脚本放置位置
若是display:none:则元素height.width为0:但去了display:none后,恢复原来大小,所以操作元素应该在去除display:none后.
- Apache 常用伪静态配置
1. /a/b?c=d => index.php?_a=a&_m=b&c=d 2. /xxx/detail-yyy.html => index.php?_a=xxx& ...
- grunt-replace和grunt-include-replace问题
关于最近在做的项目要用到的grunt-replace和grunt-include-replace,百度上很多将grunt的压缩合并的教程,可是很少讲关于这两个插件的教程,不过官网上有教程,我就是按照官 ...
- centos7 配置vnc
这是一个关于怎样在你的 CentOS 7 上安装配置 VNC 服务的教程.当然这个教程也适合 RHEL 7 .在这个教程里,我们将学习什么是 VNC 以及怎样在 CentOS 7 上安装配置 VNC ...
- JAVA的String的传值和传地址问题
关于Java的String类型,可能你会碰到这种情况,将String类型的变量传到一个函数,在这个函数中修改变量的值,但是,实参的值并没有发生改变. Java中String的传值/传地址问题: 例子引 ...
- [ASE][Daily Scrum]11.26
今天主要是修复一些历史遗留问题以及bug, 在task上进展不是很明显, 在地图与客户端同步之后产生了一些bug,例如一发子弹会消掉很多砖块,服务器地图与本地地图不同步等等... 目前的大方向分工是这 ...