【问题标题】:Top rows disappear from UITableView upon reloadData() until scrolled Up/Down顶部行在 reloadData() 时从 UITableView 消失,直到向上/向下滚动
【发布时间】:2015-09-15 18:07:59
【问题描述】:

我正在将 Web 服务中的项目加载到 iOS 应用程序中的 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

}

【问题讨论】:

  • readWithCompletion 是否在主线程中运行?

标签: ios swift list uitableview items


【解决方案1】:

试试;

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

    return cell
}

别忘了注册你的手机。

【讨论】:

  • 这是一个打字错误。它正在正确返回单元格,但仍然是同样的问题。我希望你已经看到了截图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-15
  • 1970-01-01
  • 2019-06-12
  • 1970-01-01
  • 2011-08-26
相关资源
最近更新 更多