【发布时间】: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