ios - Tableview doesn't display data in swift 2 -


i'm working on tableview in swift 2.2 in xcode 7.3.1 , i'm sure code because it's not first time me deal tableview , i'm pulling data correctly server , stored in array notice 2 function related table view not called table view appear empty me ! added cell , linked tableview view layout.

i don't know problem!

class studentteacherlist: uiviewcontroller , uitableviewdatasource,uitableviewdelegate {  @iboutlet weak var studentparenttable: uitableview!   @iboutlet weak var loadindicator: uiactivityindicatorview!     var username:string! var fromsender: string? var torec: string?  var student_id = [int]() var parent_id = [string]() var student_names = [string]() var parent_name = [string]()    //sent data var s_id:int = 0 var s_name = "" var p_id = "" var p_name = ""   override func viewdidload() {     super.viewdidload()     studentparenttable.delegate = self     studentparenttable.datasource = self       let prefs:nsuserdefaults = nsuserdefaults.standarduserdefaults()     username = prefs.objectforkey("user")as! string     fromsender = prefs.objectforkey("sender")as! string     torec = prefs.objectforkey("receiver")as! string       self.loadindicator.startanimating()      dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), { () -> void in         self.loadlist()        //self.studentparenttable.reloaddata()           dispatch_async(dispatch_get_main_queue(), { () -> void in             self.loadindicator.stopanimating()         })     });       studentparenttable.reloaddata()  }     func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {      return student_names.count }   func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     //this method define each cell @ table view     let cell = uitableviewcell(style: uitableviewcellstyle.default, reuseidentifier: "cell")       cell.textlabel?.text = student_names[indexpath.row]     cell.detailtextlabel?.text = parent_name[indexpath.row]      return cell }     override func didreceivememorywarning() {     super.didreceivememorywarning()     // dispose of resources can recreated. }  @ibaction func backbutton(sender: anyobject) {     self.dismissviewcontrolleranimated(true, completion: nil )  }    func loadlist() {     var normallink = "mylinkhere"     normallink = normallink + "?teacherid=" + self.username        var studentparenturl:nsurl = nsurl (string: normallink)!     let data = nsdata(contentsofurl: studentparenturl)!        {         let json = try nsjsonserialization.jsonobjectwithdata(data, options: .allowfragments)          if let alldata = json["data"] as? [[string: anyobject]] {             onedata in alldata {                 if let stu_id = onedata["id"] as? int {                     student_id.append(stu_id)                 }                 if let stu_name = onedata["studentname"] as? string {                     student_names.append(stu_name)                 }                 if let par_id = onedata["parentid"] as? string {                     parent_id.append(par_id)                 }                 if let par_name = onedata["parentname"] as? string {                     parent_name.append(par_name)                 }                }         }     } catch {         print("error serializing json: \(error)")     }         print(student_names.count)  }       func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) {       s_id = student_id[indexpath.row]     s_name = student_names[indexpath.row]     p_id = parent_id[indexpath.row]     p_name = parent_name[indexpath.row]  } } 

it looks aren't reloading after call:

dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_default, 0), { () -> void in         self.loadlist()        //self.studentparenttable.reloaddata()           dispatch_async(dispatch_get_main_queue(), { () -> void in             self.loadindicator.stopanimating()         })     }); 

so should add studentparenttable.reloaddata() after self.loadindicator.stopanimating().


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -