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

标签 ios uitableview

在我的代码中:

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() 没有调用 cellForRowAtIndexPathself.TableView 不是 nil,当我退出并返回时, TableView 会重新加载。有什么想法吗?

最佳答案

您需要从主线程调用 reloadData。使用

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

在您调用 reloadData 和 refreshControl 的地方。

关于ios - self.tableView.reloadData() 不调用 cellForRowAtIndexPath() Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31709419/

相关文章:

ios - 在不重新加载标题部分的情况下重新加载 UITableView

ios - UIButton 的 IBAction 导致无法识别的选择器发送到实例错误(iOS)

ios - 谷歌应用索引: GSDDeepLink call causes build to fail

iphone - 一次只展开 "one"单元格?目前我可以打开多个

ios - 展开可选 IBOutlet 值时为 Nil

iphone - 选择表格单元格时附件 View 背景消失

ios - 在 Objective-C 的 NSDocument 中存储许多图像 : [iOS]

objective-c - 表格单元格字幕不显示

ios - Swift UITableView 删除所选行及其上方的任何行

ios - 带有与 ViewController 分离的 Controller 的 UITableView