ios - Swift UITableView reloadData in a closure -
i believe i'm having issue closure happening on background thread , uitableview isn't updating fast enough. making phone call rest service , in closure have tableview.reloaddata()
phone call takes few seconds happen. how create info reload faster (perhaps on main thread?)
rest query function - using swiftyjson library decoding
func asyncflightsquery() { var url : string = "http://127.0.0.1:5000/flights" var request : nsmutableurlrequest = nsmutableurlrequest() request.url = nsurl(string: url) request.httpmethod = "get" nsurlconnection.sendasynchronousrequest(request, queue: nsoperationqueue(), completionhandler:{ (response:nsurlresponse!, networkdata: nsdata!, error: nserror!) -> void in var error: autoreleasingunsafemutablepointer<nserror?> = nil // parse swiftyjson allow json = json(data: networkdata) // empty out results array self.resultarray = [] // populate results array (key: string, subjson: json) in json["flights"] { print ("key: \(key) ") print (subjson["flightid"]) print ("\n") self.resultarray.append(subjson) } print ("calling reloaddata on table..??") self.tableview.reloaddata() }) }
once self.tableview.reloaddata()
called in debugger
uikit isn't thread safe. ui should updated main thread:
dispatch_async(dispatch_get_main_queue()) { self.tableview.reloaddata() }
ios swift
No comments:
Post a Comment