swift - Counter wont subtract on button press? -


i trying setcount -1 each time endsetpressed action called.

i have included setcount -= 1 updatetimer function when endsetpressed pressed, should -1 setcount , start restcount timer. in practice doesnt seem show doing -1 in app stays fixed @ starting setcount value.

another issue want able see value of restremainingcountdownlabel user setting reststeppervaluechanged value, figured done via 'restremainingcountdownlabel.text = string(restcount)' im using 'restcount = int(sender.value)*60' generate value in minutes, showing restremainingcountdownlabel in seconds rather mins, appreciate guidance on 1 too!

here code:

    @iboutlet weak var restremainingcountdownlabel: uilabel! @iboutlet weak var setsremainingcountdownlabel: uilabel! @iboutlet weak var numberofsetslabel: uilabel! @iboutlet weak var numberofrestlabel: uilabel! @iboutlet weak var adjustsetsstepper: uistepper! @iboutlet weak var adjustreststepper: uistepper!  var resttimer: timer? var restcount = 0 var setcount = 0  @ibaction func endsetpressed(_ sender: any) {     resttimer = timer.scheduledtimer(timeinterval: 1.0, target: self, selector: #selector(restcontroller.updatetimer), userinfo: nil, repeats: true) }  @ibaction func setsteppervaluechanged(_ sender: uistepper) {     numberofsetslabel.text = int(sender.value).description     setcount = int(sender.value)     setsremainingcountdownlabel.text = string(setcount) }  @ibaction func reststeppervaluechanged(_ sender: uistepper) {     numberofrestlabel.text = int(sender.value).description     restcount = int(sender.value)*60     restremainingcountdownlabel.text = string(restcount) }  @ibaction func resetsetsbutton(_ sender: any) {    //setcount = int }  override func viewdidload() {     super.viewdidload()  }  func updatetimer() {     if (setcount > 0){         setcount -= 1     }     if (restcount > 0){         let minutes = string(restcount / 60)         let seconds = string(restcount % 60)         restremainingcountdownlabel.text = minutes + ":" + seconds         restcount -= 1     } } 

have @ updatetimer() method, first line:

if (setcount > 0) 

if setcount > 0 subtract 1 setcount

but...here you've declared setcount value of 0

var setcount = 0 

so, never end in if part :)

how debug this

the next time have problem this, try adding print() statements code.

in case this:

@ibaction func endsetpressed(_ sender: any) {     print("endsetpressed")     resttimer = timer.scheduledtimer(timeinterval: 1.0, target: self, selector: #selector(restcontroller.updatetimer), userinfo: nil, repeats: true) }  @ibaction func setsteppervaluechanged(_ sender: uistepper) {     numberofsetslabel.text = int(sender.value).description     setcount = int(sender.value)     setsremainingcountdownlabel.text = string(setcount) }  @ibaction func reststeppervaluechanged(_ sender: uistepper) {     numberofrestlabel.text = int(sender.value).description     restcount = int(sender.value)*60     restremainingcountdownlabel.text = string(restcount) }  @ibaction func resetsetsbutton(_ sender: any) {    //setcount = int }  override func viewdidload() {     super.viewdidload() }  func updatetimer() {     print("updatetimer")     if (setcount > 0){         print("setcount > 0")         setcount -= 1         print("setcount \(setcount)")     }     if (restcount > 0){         print("restcount > 0")         let minutes = string(restcount / 60)         let seconds = string(restcount % 60)         restremainingcountdownlabel.text = minutes + ":" + seconds         restcount -= 1         print("restcount \(restcount) - minutes: \(minutes) - seconds: \(seconds)")     } } 

that should give indications going on , "path" code follows.

hope helps you.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -