[英]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.