swift - Tableview works on sim but not on test device -
i have no idea whats wrong function. i'm calling in viewdidload , prints array blank when load on phone. when in simulator fills array though. using objectmapper if helps @ all.
func getdata() { let myurlstring = "http://meetup.x10host.com/api/get_event.php?radius=15" let myurl = nsurl(string: myurlstring)! var mycardsarray = [card]() let mysession = nsurlsession(configuration: nsurlsessionconfiguration.defaultsessionconfiguration()) let mydatatask = mysession.datataskwithurl(myurl) { (data, response, error) in guard error == nil else { let alertcontroller = uialertcontroller(title: "no connection", message: "can't connect database, perhaps turn on wifi?", preferredstyle: uialertcontrollerstyle.alert) alertcontroller.addaction(uialertaction(title: "okay", style: uialertactionstyle.default,handler: nil)) self.presentviewcontroller(alertcontroller, animated: true, completion: nil) return } { let jsondata = try nsjsonserialization.jsonobjectwithdata(data!, options: nsjsonreadingoptions.allowfragments) somecard in jsondata as! nsarray{ let card = mapper<card>().map(somecard) mycardsarray.append(card!) self.namearray.append(card!.titlee!) self.textarray.append(card!.text!) self.userarray.append(card!.attending!) self.latarray.append(card!.latitude!) self.longarray.append(card!.longitude!) self.timearray.append(card!.time!) self.loctextarray.append(card!.locationtext!) dispatch_async(dispatch_get_main_queue()) { self.tableview.reloaddata() } } } catch { print("there error") } } mydatatask.resume() print(namearray) }
Comments
Post a Comment