ios - Reloading UITableView on Main Thread does not always work -


i have problem when reload data of uitableview on main queue doesn't reload data of time. reloads data around 3 out of 5 times when launch app streaks of reloading (3 5 launches) , streaks of not-reloading (2 3 launches).

i'm testing app on iphone 6 ios 8.4 , xcode 7 beta 4 using swift 2.

this code uiviewcontroller holding uitableview, initial screen app after launching.

import uikit  class tablecontroller: uiviewcontroller, cllocationmanagerdelegate {     let rowtitles = ["date", "temp", "humidity", "wind"]     var tabledata = [string : string]()      override func viewdidload() {         self.setuplocationmanager()     }      func setuplocationmanager() {          // setting location manager           self.locationmanager.startupdatinglocation()     }      func locationmanager(manager: cllocationmanager, didupdatelocations locations: [cllocation]) {         locationdata.ownlocation = locations.last!         self.locationmanager.stopupdatinglocation()          self.setuptable()     }      func setuptable() {         apiclient.getcurrentweatherandsundata(locationdata.ownlocation) { (data, error) -> void in             guard error == nil else {                 print("could not current weather , sun data")                 return             }              weatherdata.main = data!.valueforkey("main") as! dictionary<string, anyobject>             weatherdata.wind = data!.valueforkey("wind") as! dictionary<string, anyobject>              self.setweatherdata()              dispatch_async(dispatch_get_main_queue(), { () -> void in                 self.owntableview.reloaddata()             })         }     }      func setweatherdata() {         let temp = string(weatherdata.main["temp"] as! int)         let humidity = string(weatherdata.main["humidity"] as! int)         let windspeed = string(weatherdata.wind["speed"] as! int)          self.tabledata["date"] = getdatestringwithformat(nsdate(), formatstring: "dd.mm.yyyy")         self.tabledata["temp"] = "\(temp)°"         self.tabledata["humidity"] = "\(humidity)%"         self.tabledata["wind"] = "\(windspeed) km/h"     } }  extension tablecontroller: uitableviewdatasource, uitableviewdelegate {     func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int {         return self.rowtitles.count ?? 0     }      func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {         let myreuseidentifier = "reuseidentifierprayertimes"         var cell = tableview.dequeuereusablecellwithidentifier(myreuseidentifier) uitableviewcell!          if cell == nil {             cell = uitableviewcell(style: uitableviewcellstyle.value2, reuseidentifier: myreuseidentifier)             cell.textlabel!.font = uifont(name: cell.textlabel!.font.fontname, size: 17.0)             cell.detailtextlabel!.font = uifont(name: cell.detailtextlabel!.font.fontname, size: 17.0)         }          let rowtitle = self.rowtitles[indexpath.row]         let rowdata = self.tabledata[rowtitle]          cell!.textlabel!.text = rowtitle         cell!.detailtextlabel!.text = rowdata          return cell     } } 

the problem though reloaddata() function called on main thread , called after setting values table in setweatherdata(), table on iphone doesn't show data.

the table indeed show data if , go tab , come back:

override func viewdidappear() {     self.owntableview.reloaddata() } 

my question whether can find cause random behavior. had assumption reloaddata() call comes after initial loading of table , therefore disregarded. how organize api call subsequent data reloading of uitableview after app launch?

so, problem added prototype uitableviewcell uitableview in interface builder (ib) of xcode 7 beta 4. don't know why, adding prototype uitableviewcell uitableview in ib caused problems in uitableviews. after deleting prototype uitableviewcells again uitableviews in project in ib works fine. way code creates couple of uitableviewcells upon launch , reuses them if change data , call reloaddata() on uitableview.


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -