简体   繁体   English

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

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

In my code: 在我的代码中:

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()

The line self.tableView.reloadData() does not call cellForRowAtIndexPath . self.tableView.reloadData()行不调用cellForRowAtIndexPath self.TableView is not nil, and the table view reloads when I exit it and go back. self.TableView不是nil,退出后返回时,表视图会重新加载。 Any ideas? 有任何想法吗?

You need to call reloadData from the main thread. 您需要从主线程调用reloadData。 Use 采用

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

in the spot where you were calling reloadData and refreshControl. 在调用reloadData和refreshControl的地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 self.tableView.reloadData() 在 Swift 中不起作用 - self.tableView.reloadData() not working in Swift 在ViewController中连接TableView-self.tableView.reloadData()在Swift中不起作用 - Connecting TableView within ViewController - self.tableView.reloadData() not working in Swift self.tableView.reloadData()无法正常工作 - self.tableView.reloadData() not working Swift-self.tableview.reloaddata()在Master Detail应用程序上不起作用 - Swift - self.tableview.reloaddata() not working on Master Detail Application 日志 - DispatchQueue - self.tableView.reloadData() 未被调用 - Journal - DispatchQueue - self.tableView.reloadData() not being called Swift-Xcode:为什么不是我的self.tableView.reloadData()调用将承诺的数据加载到我的表/单元格中? - Swift-Xcode: why isn't my self.tableView.reloadData() call loading the promised data into my table / cells? 删除列表后,UITableView将不会刷新。 self.tableView.reloadData()也不起作用 - UITableView will not refresh once list is deleted. self.tableView.reloadData() does not work either tableView reloadData cellForRowAtIndexPath未调用 - tableView reloadData cellForRowAtIndexPath not called reloadData不调用cellForRowAtIndexPath - reloadData not calling cellForRowAtIndexPath reloadData没有调用cellForRowAtIndexPath - reloadData is not calling cellForRowAtIndexPath
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM