Ios 当在表格视图中滚动时,计时器将重置为表格视图单元格中的原始值
我有作业列表(表视图),当我点击任何作业时,这意味着我申请了作业,然后计时器启动(30秒倒计时),在此范围内,我可以撤消可能申请的作业。我在每个单元上都有单独的计时器。 我使用了2秒的定时器函数来重新加载表视图 行代码的单元格如下所示:Ios 当在表格视图中滚动时,计时器将重置为表格视图单元格中的原始值,ios,swift,timer,tableview,reset,Ios,Swift,Timer,Tableview,Reset,我有作业列表(表视图),当我点击任何作业时,这意味着我申请了作业,然后计时器启动(30秒倒计时),在此范围内,我可以撤消可能申请的作业。我在每个单元上都有单独的计时器。 我使用了2秒的定时器函数来重新加载表视图 行代码的单元格如下所示: if data.current_state != 1{ if data.isApplied == true { if cell.countdowlLbl.text != "00:00" || ce
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