簡體   English   中英

self.tableView.reloadData()不調用cellForRowAtIndexPath()Swift

[英]self.tableView.reloadData() not Calling cellForRowAtIndexPath() Swift

在我的代碼中:

let url = NSURL(string: "http://localhost:8080/files/")
let request = NSMutableURLRequest(URL: url!)
request.HTTPMethod = "GET"
var task = NSURLSession.sharedSession().dataTaskWithRequest(request, completionHandler: {data, response, error -> Void in
let array = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: nil) as! NSArray
files = []
for element in array {
    let dict = NSJSONSerialization.JSONObjectWithData((element as! String).dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!, options: nil, error: nil) as! NSDictionary
    files.append(File(fileName: dict["name"] as! String, body: dict["body"] as! String))
}
self.tableView.reloadData()
self.myRefreshControl.endRefreshing()
})
task.resume()

self.tableView.reloadData()行不調用cellForRowAtIndexPath self.TableView不是nil,退出后返回時,表視圖會重新加載。 有任何想法嗎?

您需要從主線程調用reloadData。 采用

dispatch_async(dispatch_get_main_queue()) {
    self.tableView.reloadData()
    self.myRefreshControl.endRefreshing()
}

在調用reloadData和refreshControl的地方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM