swift - UITableView.reloadData() is not working -


i've uitableview gets dynamic values. these values depends on user entry. user enters string , code gets array internet using string. in view, uitableview , textfield working on same view in screenshot. when press tower(gettowerbutton()) button, uitableview should reload data reloaddata(). it's not reloading, because doesn't print 1 , 2.

note: if seperate uitableview , user entry 2 different views code works. , table loads.

class addtowerviewcontroller: uiviewcontroller, uitextfielddelegate, uitableviewdelegate, uitableviewdatasource {       @iboutlet weak var icaocodefield: uitextfield!     @iboutlet weak var towerstable: uitableview!     var towersarray: array<string> = []     override func viewdidload() {         super.viewdidload()         self.icaocodefield.delegate = self                  // additional setup after loading view.     }      override func didreceivememorywarning() {         super.didreceivememorywarning()         // dispose of resources can recreated.     }         @ibaction func gettowers() {         towersarray = gettowernames(icaocode: icaocodefield.text!)         self.towerstable.reloaddata()     }       func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {         let cell = towerstable.dequeuereusablecellwithidentifier("cellos", forindexpath: indexpath) uitableviewcell         cell.textlabel?.text = towersarray[indexpath.row]         return cell     }      func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {         return towersarray.count     } ... 

view

edit: i've noticed when seperate uitableview , user entry view table loads data. guess problem causes because system runs numberofrowsinsection , cellforrowatindexpath methods @ first launch of belonging view.

you're saying gettowernames(icaocode: icaocodefield.text!) loads data internet , don't think doing synchonously. suggest create completion block handle request's response. this:

gettowernames(icaocode: icaocodefield.text!, completion:(names: array<string>) -> ()) 

then use completion closure reload table.

gettowernames(icaocode: icaocodefield.text!) {[weak self] names in      self?.towernamearray = names     self?.tableview.reloaddata()  } 

hope helps.


Comments