*行在reloadData()上从UITableView消失,直到滚动向上/向下

问题描述:

我在iOS应用程序中将项目从Web服务加载到UITableView。 这里的问题是,只要数据被加载,顶部可见的不滚动的行数就不可见。该页面变为空白。 如果我向下滚动,下面的图像会完美加载。再次滚动顶部图像也会正确加载。*行在reloadData()上从UITableView消失,直到滚动向上/向下

详细截图链接:https://www.dropbox.com/sh/nfxcgw2ple8g4mt/AAAOTswWDEN-s2-dAbJ1bHu7a?dl=0

class FirstViewController: UIViewController, UITableViewDataSource, UITableViewDelegate{ 

    override func viewDidLoad() { 
     super.viewDidLoad()[1] 

//  self.client = xxxxxxxxxxxx; 

// 
// fetching from server logic query 
// 
//    
    query.readWithCompletion({ (result , error) -> Void in 

      if (error == nil) 
      { 
       self.activityIndicatorView.hidden = true // loading indicator 
       self.allResults = result.items 
        println(self.allResults!.count) 
       self.tableView.hidden = false 
       self.tableView.reloadData() 
      } 
      else{ 
       println(error.localizedDescription) // error 
      } 

     }) 

    } 

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
    { 
     if (allResults != nil) { return self.allResults.count } 
     else { return 0 } 
    } 

    func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
    { return 200 } 

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    { 
     var cell: CellClass = self.tableView.dequeueReusableCellWithIdentifier("item") as! CellClass 

     return cell //typo 

} 
+1

readWithCompletion是否在主线程中运行? – Arsen

尝试;

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell { 
    let cell:CellClass = tableView.dequeueReusableCellWithIdentifier("item", forIndexPath: indexPath) as! CellClass 

    return cell 
} 

不要忘了注册你的手机。

+0

这是一个打字错误。它正确地返回细胞,但仍然是同样的问题。我希望你看过截图。 – AqibBangash