Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/104.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 为什么我的电池不能同时加载?_Ios_Swift_Multithreading_Uitableview_Asynchronous - Fatal编程技术网

Ios 为什么我的电池不能同时加载?

Ios 为什么我的电池不能同时加载?,ios,swift,multithreading,uitableview,asynchronous,Ios,Swift,Multithreading,Uitableview,Asynchronous,我使用后台线程从网络获取数据,使用主线程显示单元格: dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), { let _ = self.http.getInfo() { (result) in self.cellsArray = result dispatch_async(dispatch_get_main_queue(), { self.table

我使用后台线程从网络获取数据,使用主线程显示单元格:

dispatch_async(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), {
    let _ = self.http.getInfo() { (result) in
        self.cellsArray = result

        dispatch_async(dispatch_get_main_queue(), {
            self.tableView.reloadData()
        })
        completion(completed: true)
    }
})
其中,
self.http.getInfo
是获取网络信息的
nsursession.sharedSession().dataTaskWithRequest
方法

当我运行我的应用程序时,我的单元格开始分别显示为:第一个出现,一秒钟后下一个出现,2秒钟后下一个出现,等等

为什么它们不同时出现?而且,由于使用了后台和主线程,当我实现无限滚动并将新单元格附加到现有单元格数组时,我的UITableView会跳转


如何修复它?

NSURLSession.sharedSession().dataTaskWithRequest的完成处理程序中写入
self.tableView.reloadData()
此语句。但是如何从另一个文件更新我的tableView呢?我有两个文件:Network和UITableViewController。在网络文件中,我使用请求执行数据任务,并将其显示在UITableViewController中。我试图通过NSNotificationCenter从网络文件重新加载我的tableView,但它仍然存在错误和跳跃。我添加了它,如下所示
completion(结果:topNews)NSNotificationCenter.defaultCenter().postNotificationName(“refreshMyTableView”,对象:nil)