ios - Dynamically Calculate Pace in Swift -


i have code below. how dynamically calculate pace fill in fields instead of having calculate manually tapping on calculate pace button?

import uikit  class viewcontroller: uiviewcontroller {      @iboutlet weak var mintextfield: uitextfield!     @iboutlet weak var sectextfield: uitextfield!     @iboutlet weak var disttextfield: uitextfield!     @iboutlet weak var pacelabel: uilabel!       func paceinseconds (minutes:double, seconds: double, distance: double) -> double {         return ((minutes*60) + seconds) / distance     }       @ibaction func pacecalculator(sender: uibutton) {         var paceminutes = paceinseconds(((mintextfield.text nsstring).doublevalue, seconds: (sectextfield.text nsstring).doublevalue, distance: (disttextfield.text nsstring).doublevalue)) / 60          var roundedpaceminutes = double(floor(paceminutes))         var decimalpaceseconds = paceminutes - roundedpaceminutes         var intpaceminutes = int(floor(roundedpaceminutes))         var paceseconds = int(floor(decimalpaceseconds * 60))         var pacesecondszero = string(format: "%02d", paceseconds)          pacelabel.text = "\(intpaceminutes):\(pacesecondszero)/km"     }     } 

here's storyboard ui: enter image description here

you can use various functions of uitextfielddelegate protocol. if assign view controller delegate of text field, able act upon changes in text field.

in case, should implement textfield:shouldchangecharactersinrange:replacementstring: function.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -