uilabel - Swift, Label not refreshing while in callback function -
i want change/reload label on activity indicator while running on loop. not reloading because of “self.netutil.callwebservice(urlstr) {(data)” presume.
my code below —————————————
if netutil.isconnectedtonetwork() == true { self.showactivityindicator(self.view,message: "synch progress...") //logic toc web service var urlstr: string = "\(constants.server_url)" self.container.addsubview(self.lblprocess) self.netutil.callwebservice(urlstr) {(data) -> void in self.filemgr.createfiledirectory("/surveyor") self.filepath = self.filemgr.createfile(self.filemgr.getsurveyourproplistxmlname("")) self.filemgr.writefile(data, filenamepath: self.filemgr.getsurveyourproplistxmlname("")) self.xmlnsdata = data.datausingencoding(nsutf8stringencoding)! self.beginparsing() self.loadpropertymap() var unitcount = 0 prop: property in self.properties { unitcount++ view in self.view.subviews { if view uilabel { view.removefromsuperview() } } /* refresh label code start here */ dispatch_async(dispatch_get_main_queue(), { //run ui updates self.unitcount++ println("unitcount \( self.unitcount)") var totcount = self.properties.count var message = "synchronization \(self.unitcount)/\(totcount) buildings completed" self.lblprocess.text = message self.lblprocess.setneedsdisplay() }) /* refresh label code end here */ //backup code shfted while pushing in web service self.filemgr.getsurveyorunitfiles("", procode: prop.procode string, iscreatebackup: true) //back code ended self.callunitswebservice(prop.procode string) //another web service cal } self.lblprocess.removefromsuperview() self.hideactivityindicator() }
output println attached
properties count > 10 unitcount 1 unitcount 2 unitcount 3 unitcount 4 unitcount 5 unitcount 6 unitcount 7 unitcount 8 unitcount 9 unitcount 10
if putting label out of loop reloading… should reload label in loop changes when each loop gets excited?
thanks in advance
you can refresh ui main thread.
the self.netutil.callwebservice(urlstr) {(data) -> void in}
runs block, not in main thread.
you have within block:
//logic synchronization web service var urlstr: string = "\(constants.server_url)" //add view. don't forget remove when looping done. self.container.addsubview(self.lblprocess) self.netutil.callwebservice(urlstr) {(data) -> void in //i suspect method reason why label not refreshing self.beginparsing() var unitcount = 0 prop: property in self.properties { unitcount++ view in self.view.subviews { if view uilabel { view.removefromsuperview() } } /* refresh label code start here */ dispatch_async(dispatch_get_main_queue(), { //run ui updates var totcount = self.properties.count var message = "synchronization \(unitcount)/\(totcount) buildings completed" self.lblprocess.text = message self.lblprocess.setneedsdisplay() }) /* refresh label code end here */ //backup code shfted while pushing in web service self.filemgr.getsurveyorunitfiles("", procode: prop.procode string, iscreatebackup: true) //back code ended self.callunitswebservice(prop.procode string) //another web service cal } self.hideactivityindicator() }
Comments
Post a Comment