ios - UISlider ValueChanged action not working -


i want calculate number in real-time uislider, method:

@ibaction func hpslidervaluechanged(_ sender: customuislider) {      calculator.hppercentage = double(hpslider.value)     hpvalue.text = string(int(hpslider.value * 100)) + " %"     resultlabel.text = string(calculator.calculate()) } 

both hpvalue label , resultlabel expected change value when user swipes on slider, however, hpvalue label changes, resultlabel doesn't work.

calculator not nil, here's code:

class turretdivecalculator {  var hero: heroes = .taka var build = [defenseitems](repeatelement(defenseitems(name: "empty item", index: 0, price: 0, image: #imageliteral(resourcename: "emptyitem")), count: 6)) var hppercentage: double = 0  func calculate() -> int {     let basehp = hero.hplow + (hero.hphigh - hero.hplow) / 12 * double(hero.level)     let basedefense = hero.armorlow + (hero.armorhigh - hero.armorlow) / 12 * double(hero.level) + hero.shieldlow + (hero.shieldhigh - hero.shieldlow) / 12 * double(hero.level)      var buildhp = 0.0     var builddefense = 0.0     item in build {         builddefense += item.armor         builddefense += item.shield         buildhp += item.hp     }      let fullhp = basehp + buildhp     var hp = fullhp     let defense = basedefense + builddefense     var numberofshots = 0      while hp > 0 {         let pershotdamageraw: double = 330 + double(numberofshots) * 0.09 * fullhp         let mitigateddamage: double = 0.09 * pershotdamageraw + 0.9 * pershotdamageraw / (100 + defense) * 100          hp -= mitigateddamage         numberofshots += 1     }      return numberofshots }  } 

how resultlabel's value change in real-time, too?

as can seen in chat, managed find problem.

this answer general debugging tips , tricks when problem arises.

the original problem was:

now hpvalue label changes, resultlabel doesn't work.

lets find out problem is. here's code:

resultlabel.text = string(calculator.calculate()) 

two things can go wrong here:

  1. the resultlabel not wired. see if case, try setting value plain ol' string , see if can see that. can, well, textfield wired properly.

  2. the calculate() method returns unexpected value. try verifying method returns adding print statement before return

and can see in chat, once we'd isolated problem occurred easier @bright-future track down issue.

hope helps when trying debug problem :)


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 -