ios - 当在表格视图中滚动时计时器重置为表格视图单元格中的原始值
问题描述
我有工作列表(表格视图),当我点击任何工作时,这意味着我申请了工作,然后计时器开始(倒计时 30 秒)在此我可以撤消可能申请的工作。我在每个单元格上都有单独的计时器。我使用 2 秒计时器功能重新加载表格视图。
行代码的单元格如下:
if data.current_state != 1{
if data.isApplied == true
{
if cell.countdowlLbl.text != "00:00" || cell.countdowlLbl.isFinished != true
{
cell.applyBtn.isHidden = true
cell.appliedUiView.isHidden = false
cell.AfterAppliedView.isHidden = true
}
else
{
data.current_state = 1
cell.applyBtn.isHidden = true
cell.appliedUiView.isHidden = true
cell.AfterAppliedView.isHidden = false
}
}else{
cell.appliedUiView.isHidden = true
cell.applyBtn.isHidden = false
cell.AfterAppliedView.isHidden = true
}
}else{
cell.AfterAppliedView.isHidden = false
cell.appliedUiView.isHidden = true
cell.applyBtn.isHidden = true
}
解决方案
class TimerCell: UITableViewCell
{
var timer = Timer()
var counter = 0
@IBOutlet weak var btnStartTimer: UIButton!
@IBOutlet weak var lblTimer: UILabel!
func startTimer()
{
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(actiontimer), userInfo: nil, repeats: false)
lblTimer.text = "\(timer)"
}
@objc func actiontimer() {
counter += 1
lblTimer.text = "\(counter)"
}
}
- Create timer with particular cell using table view cell class and start
timer on when select job. so, it's start only for that selected job .
- And Create all cell with different identifier like:
tbl_Job.register(UINib(nibName: "TimerCell", bundle: nil), forCellReuseIdentifier: "TImerCell\(indexPath)")
let cell = tbl_Job.dequeueReusableCell(withIdentifier: "TImerCell\(indexPath)", for: indexPath) as! TimerCell
推荐阅读
- excel - AutoLisp 将特定行的块属性 ID 名称和块计数传递给 GetExcel 例程的“Putcell”命令
- console - 我想使用 close 方法关闭我的控制台。不是通过 X
- javascript - 为什么我的 redux reducer 没有设置正确的状态?
- ionic-framework - 离子中的离子分裂窗格行为
- javascript - How do I get the output to display inside the div after the user fills in the prompts?
- python - django.db.utils.ProgrammingError:(1146,“表'lab_equipment.lab_add'不存在”)
- html - 用于 mvc 的 html 中的中心页面列表
- python-3.x - threading.Lock 实际上是如何工作的?(有多种场景)
- python - 当我尝试打开程序时,Pyinstaller 会关闭我的程序
- jenkins - 在 Windows 10 中安装 Jenkins 后无法找到 InitialAdminPassword 文件