我有一个 collectionView,我有两个问题。首先,滚动太滞后。我的 collectionView 从 url 中的 API 接收数据,如下所示:

这是我的代码:
extension ViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if imageUrl.count >= 4 {
activity.stopAnimating()
activity.isHidden = true
}else{
DispatchQueue.main.async {
self.myCollectionView.reloadData()
}
}
return imageUrl.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = myCollectionView.dequeueReusableCell(withReuseIdentifier: "myViewCell", for: indexPath) as! myViewCell
if let url = NSURL(string: imageUrl[indexPath.row]){
if let data = NSData(contentsOf: url as URL){
cell.carImageView.contentMode = UIViewContentMode.scaleAspectFit
cell.carImageView.image = …Run Code Online (Sandbox Code Playgroud)