ios - The app always shows me the answer of the first -
i made calculator converts units of measurement. app shows me answer of first (km), unless whole answer. hope 1 of find mistake.
class viewcontroller: uiviewcontroller, uipickerviewdelegate, uipickerviewdatasource { @iboutlet var label: uilabel! @iboutlet var picker1: uipickerview! @iboutlet var num: uitextfield! var array1 = ["km","m","dm","mm"] var placeanswer = 0 var answer = float() override func viewdidload() { super.viewdidload() } override func didreceivememorywarning() { super.didreceivememorywarning() } func pickerview(pickerview: uipickerview, titleforrow row: int, forcomponent component: int) -> string? { return array1[row] } func pickerview(pickerview: uipickerview, numberofrowsincomponent component: int) -> int{ return array1.count } func numberofcomponentsinpickerview(pickerview: uipickerview) -> int{ return 1 } @ibaction func submit(sender: anyobject) { if(placeanswer==0){ let numberformatter = nsnumberformatter() numberformatter.numberstyle = .decimalstyle let number = numberformatter.numberfromstring(num.text!) answer = number!.floatvalue answer = answer * 0.0001 label.text = ("\(answer)"+"km") answer = 0 } else if(placeanswer==1) { let numberformatter = nsnumberformatter() numberformatter.numberstyle = .decimalstyle let number = numberformatter.numberfromstring(num.text!) answer = number!.floatvalue answer = answer * 100 label.text = ("\(answer)" + "m") answer = 0 } else if(placeanswer==2) { let numberformatter = nsnumberformatter() numberformatter.numberstyle = .decimalstyle let number = numberformatter.numberfromstring(num.text!) answer = number!.floatvalue answer = answer * 10 label.text = ("\(answer)" + "dm") answer = 0 } else { let numberformatter = nsnumberformatter() numberformatter.numberstyle = .decimalstyle let number = numberformatter.numberfromstring(num.text!) answer = number!.floatvalue answer = answer / 10 label.text = ("\(answer)"+"mm") answer = 0 } } }
because value of placeanswer
is not changing anywhere in code.
use set value
func pickerview(pickerview: uipickerview, didselectrow row: int, incomponent component: int){ placeanswer = row }
Comments
Post a Comment