私は時間に異なる瞬間に作成されUITableViewcells
を持っていると私はそれらの一つ一つが、オブジェクトがreloadData()
複数のタイマ(スウィフト)
これが何であるかに追加されたときにトリガーする独立したタイマーを持っていると思います私は新しいセルを作成するたびconfigureLiveCell
が呼び出されるときに問題が来るこれまで
import UIKit
var timer = Timer()
var blinkStatus:Bool! = false
var time = 300
class LiveViewCell: UITableViewCell {
let str = String(format:"%02d:%02d", (time/60), (time % 100))
func processTimer() {
if time > 0 {
time -= 1
timeRemainingLbl.text = String(time)
} else if time == 0 {
timer.invalidate()
timeRemainingLbl.text = "Due!"
timer = Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(LiveViewCell.blinkTimer), userInfo: nil, repeats: true)
}
}
func blinkTimer() {
if blinkStatus == false {
timeRemainingLbl.textColor = UIColor(red:1.00, green:0.00, blue:0.00, alpha:1.0)
blinkStatus = true
} else if blinkStatus == true {
timeRemainingLbl.textColor = UIColor.clear
blinkStatus = false
}
}
@IBOutlet weak var tableNumberLeftLabel: UILabel!
@IBOutlet weak var guestNumbersLabel: UILabel!
@IBOutlet weak var timeInTableLabel: UILabel!
@IBOutlet weak var tableNumberLbl: UILabel!
@IBOutlet weak var timeRemainingLbl: UILabel!
var table: Table!
func configureLiveCell(_ NT: Table) {
layer.cornerRadius = 20
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(LiveViewCell.processTimer), userInfo: nil, repeats: true)
tableNumberLbl.text = "T" + String(NT.number)
timeRemainingLbl.text = String(time)
}
}
を行っています。タイマーはスピードアップしているようですが、私は各タイマーを独立させたいと思います。
prepareForReuse()はどこに置く必要がありますか? – Christian
あなたのセルクラスで。 – rmaddy
これは動作しますが、別のView Controllerに行くたびに、すべてのセルが追加されてスピードアップします。私はこのLiveViewCellがすべてのviewControllersに表示されているとは言及していません – Christian