Swift and swiftcode

Source: Internet
Author: User

Swift and swiftcode

Swift-UITableViewCell countdown reuse Solution

 

Effect

 

Source code

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

/// CountDownTimerController. swift // Swift-Animations // Created by YouXianMing on 16/9/4. // Copyright©2016 YouXianMing. All rights reserved. // import UIKitclass 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: String, countdownTime: Int) {timesArray. append (CountDownTimeCell. adapter (data: TimeModel (title: title, countdownTime: countdownTime)} add (title: "YouXianMing", countdownTime: 20034) add (title: "Aaron", countdownTime: 31) add (title: "Nicolas", countdownTime: 1003) add (title: "Quentin", countdownTime: 394) add (title: "Samirah", countdownTime: 345345) add (title: "Serafina", countdownTime: 233) add (title: "Shanon", countdownTime: 4649) add (title: "Sophie", countdownTime: 3454) add (title: "Steven", countdownTime: 54524) add (title: "Saadiya", countdownTime: 235) // Create TableView. tableView = UITableView (frame :( ContentView ?. Bounds )!) TableView. delegate = self tableView. dataSource = self tableView. separatorStyle =. None tableView. rowHeight = 60 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? TimeModel {model. countDown ()} DefaultNotificationCenter. postMessageTo (icationicationevent. 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 {retur N tableView. Partition (timesArray [indexPath. row], indexPath: indexPath)} func tableView (tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {(cell! CustomCell). display = true} func tableView (tableView: UITableView, didEndDisplayingCell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {(cell! CustomCell). display = false }}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.