Swift,swiftcode

來源:互聯網
上載者:User

Swift,swiftcode

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 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 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: "Nicholas",    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 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    }}

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.