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. ADO.NET Entity Framework学习笔录(一)

    今天开始学习了EF的相关内容,以前只知道ADO.NET,今天学习后觉得有必要写个相关的学习心得,今天就先写第一篇. 我们的再学习的过程中所用到的环境是Windows7+SQLServer2008+VS ...

  2. AngularJs的$http使用随笔

    AngularJs的$http服务是Angularjs自带的核心服务之一,用来与HTTP远程服务器交互. 关于$http使用,我体会的一下几点注意: 1.在使用是报“Uncaught Referenc ...

  3. 说说ID选择符、类选择符和HTML标记选择符的优先级顺序

    ID选择符.类选择符和HTML标记选择符三者之间的优先级顺序是:ID选择符>类选择符>HTML标记选择符,但是可以用!important提升优先权. 如:       p{color:#f ...

  4. UIScrollView详解

    1.UIScrollView常用属性 contentSize属性--该属性表示滚动的内容的范围大小,是CGPoint类型的. 说明: 默认超出UIScrollView的可视区域的内容是不显示的.相当于 ...

  5. JAVA的String的传值和传地址问题

    关于Java的String类型,可能你会碰到这种情况,将String类型的变量传到一个函数,在这个函数中修改变量的值,但是,实参的值并没有发生改变. Java中String的传值/传地址问题: 例子引 ...

  6. HALCON-FUZZY检测用于开关引脚测量

    跟我学机器视觉-HALCON学习例程中文详解-FUZZY检测用于开关引脚测量 * This example program demonstrates the basic usage of a fuzz ...

  7. javascript 中的console.log和弹出窗口alert

    主要是方便你调式javascript用的.你可以看到你在页面中输出的内容. 相比alert他的优点是: 他能看到结构话的东西,如果是alert,淡出一个对象就是[object object],但是co ...

  8. Android编译错误, Ignoring InnerClasses attribute for an anonymous inner class

    今天在做android项目时,加入第三方包,一编译就报错.错误如下:[2012-01-13 14:51:25 - xxx] Dx warning: Ignoring InnerClasses attr ...

  9. WP8:在Unity中使用OpenXLive

    Unity 4.2正式版开始添加了对Windows 8.Windows Phone 8等其他平台的支持,而且开发者可以免费使用Unity引擎来开发游戏了.而作为Windows Phone和Window ...

  10. Javascript 异步加载详解(转)

    本文总结一下浏览器在 javascript 的加载方式. 关键词:异步加载(async loading),延迟加载(lazy loading),延迟执行(lazy execution),async 属 ...