因此,由于索引超出范围问题,刷新功能不断使我的应用程序崩溃。然后我在第一次清空我的列表后添加了 reloadData。现在我在刷新时得到这个闪烁,因为它首先加载空列表然后加载填充列表。我应该在哪里清空列表或如何摆脱闪烁?我正在使用 swift 3 和 Xcode 8.2.1
func getData()
{
fetchedUsers.removeAll()
self.userTableView.reloadData()
//myphpfileurl
var request = URLRequest(url: URL(string: url)!)
request.httpMethod = "GET"
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration, delegate: nil, delegateQueue: OperationQueue.main)
let task = session.dataTask(with: request) { (data, response, error) in
if (error != nil) {
print("Error")
}
else{
do{
let fetchedData = try JSONSerialization.jsonObject(with: data!, options: .mutableLeaves) as! NSArray
for eachFetchedUsers in fetchedData {
let eachUsers = eachFetchedUsers as! [String : Any]
let id = eachUsers["id"] as! String
let name = eachUsers["Nimi"] as! String
let email = eachUsers["Sahkoposti"] as! String
let company = eachUsers["Yritys"] as! String
self.fetchedUsers.append(Users(id : id, name: name, email : email, company: company))
}
self.userTableView.reloadData()
self.refreshControl.endRefreshing()
}
catch{
print("Error 2")
}
}
}
task.resume()
}
像这样尝试重新加载表格
DispatchQueue.main.async {
self.userTableView.reloadData()
self.refreshControl.endRefreshing()
}
关于ios - 刷新tableView刷新数据时闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43608034/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |