0
我正在构建一个国家选择器UITableViewController
,其中每个UITableViewCell
包含该国的国旗UIImage
。我试图在主线程加载每个单元的从.xcassets
UIImage
对象在我tableView(_:cellForRowAt:)
,像这样:快速从磁盘加载UITableViewCell图像
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
let imageName = UIImage(named: "US.png")
imageView?.image = UIImage(named: imageName)
return cell
}
这将产生大约〜46的FPS。然后我尝试异步操作:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
DispatchQueue.main.async {
let imageName = UIImage(named: "US.png")
imageView?.image = UIImage(named: imageName)
}
return cell
}
它将我的滚动FPS提高到55,这并不可怕。但我认为它可以进一步优化。
从高性能可滚动的UITableView
中快速加载磁盘映像的最佳方式是什么?第三方库?