progress bar - Unrecognized selector for instance error Swift -
im creating simple typing app timer. timer should in form of progress bar decrements every second.
to implement progressbar, intended set progress 0.1 lesser current progress every 1 second. there "unrecognized selector instance " error when set progress. there other way work around.
import foundation import uikit class testview: uiviewcontroller, uitextinputtraits { @iboutlet weak var testlabel: uilabel! @iboutlet weak var typingfield: uitextfield! @iboutlet weak var progressview: uiprogressview! var time : float = 0.0 var timer: nstimer! var test = 0; var progress : float = 1 var mymutablestring = nsmutableattributedstring() var teststringarray = ["abode" , "tutorial" , "completed", "war", "method", "continue", "machine", "texting" , "iterate"] var idx = 0; var setprog : float = 1 func textfielddidchange(textfield: uitextfield) { let s = typingfield.text! if(s.characters.last == " "){ let word = s.stringbytrimmingcharactersinset(nscharacterset.whitespacecharacterset()) if(!word.isempty){ print(teststringarray[idx]) if(word == teststringarray[idx]){ idx++; typingfield.text = ""; testlabel.text = teststringarray[idx]; }else{ typingfield.text = ""; } } } } func setprogress() { setprog -= 0.1 progressview.progress = setprog <-- cannot decrement progress bar } override func viewdidload() { super.viewdidload() typingfield.autocorrectiontype = .no typingfield.autocapitalizationtype = .none timer = nstimer.scheduledtimerwithtimeinterval(1, target: self, selector:selector("setprogress"), userinfo: nil, repeats: true) testlabel.text = teststringarray[idx]; typingfield.addtarget(self, action: "textfielddidchange:", forcontrolevents: uicontrolevents.editingchanged) } override func didreceivememorywarning() { super.didreceivememorywarning() // dispose of resources can recreated. } }
you have coded scheduledtimerwithtimeinterval
in manner done objective-c. in swift done differently. instead of:
selector:selector("setprogress")
just use:
selector:"setprogress"
Comments
Post a Comment