Я создаю приложение с UICollectionView, которое показывает различные веб-сайты из массива (я уверен, что нет повторяющихся ссылок !!)
у меня проблема с дубликатом UICollectionViewCells, показывающим тот же веб-сайт, когда я быстро прокручиваю ...
Я прочитал все ответы о том, как решить ту же проблему для дубликатов "изображений" в UICollectionView
но я не мог сделать то же самое для моих сайтов
это мой массив сайтов и viewDidLoad:
let caocapWEB = ["https://qasr-alaros.com", "https://missfeionkah.com", "https://zid.store/dal-accessories", "https://gumesh.com", "https://cnds.co", "https://nano-eshop.com","http://zf-lc.net", "https://carbonfibreauto.com","https://syarah.com", "https://procaresa.com","https://www.liqui-moly.com", "https://www.niceonesa.com","https://www.alkhdmah.com", "http://alsoukalsaudi.com","https://kyzstore.com", "http://www.otlobli.com","https://munwradates.store", "http://www.bakerycup.com.sa","https://tarafcoco.com", "https://uae.souq.com/ae-en/","http://bassurah.com", "https://raseel.gift","https://www.cvmaker.info", "http://osos-edu.com","http://www.careery.com", "http://samaacademic.net","http://btfconsult.com", "https://www.ghanaty.com","https://www.bilsaan.com", "https://glamourbeauty.com","http://marianinos.com", "https://arttime.sa","https://salla.sa/monwhite_shop", "http://shop.kawtherart.com","https://www.sokkat-alteeb.com", "https://mna9rr.com","https://mefateeh.com", "https://salla.sa/m_tiqani","https://fitneeds.sa", "https://salla.sa/slk.sha7n","https://grazie.me", "https://cd-k.com","https://hl2.store", "https://lantanaashop.com","https://quick.sa.com/home_en/", "https://business1409.com","http://www.saudi-dsc.com", "http://www.hotelzgroup.com","http://www.tafassell.com", "https://9200.co","https://www.mhatat.com", "http://cptltd.com","https://www.barigallery.com", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "","", "", ""]
override func viewDidLoad() {
super.viewDidLoad()
caocapsCollectionView.delegate = self
caocapsCollectionView.dataSource = self
caocapsCollectionView.register(UINib.init(nibName: "caocapCell", bundle: nil), forCellWithReuseIdentifier: "caocapCell")
}
это мое расширение для кода collectionView:
extension ExploreVC: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return caocapWEB.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let caocap = caocapWEB[indexPath.row]
guard let cell = caocapsCollectionView.dequeueReusableCell(withReuseIdentifier: "caocapCell", for: indexPath) as? caocapCell else { return UICollectionViewCell() }
let theURL = URL(string: caocap)
let defaultValue = URL(string: "https://ficruty.wixsite.com/caocap")!
var urlRequest = URLRequest(url: theURL ?? defaultValue)
urlRequest.cachePolicy = .returnCacheDataElseLoad
cell.configureCell(website: urlRequest)
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let numberOfColumns: CGFloat = 2
let width = collectionView.frame.size.width
let height = collectionView.frame.size.height
let xInsets: CGFloat = 10
let cellspacing: CGFloat = 5
return CGSize(width: (width / numberOfColumns) - (xInsets + cellspacing ) , height: height / 1.8 )
}
и это мой код UICollectionViewCell:
import UIKit
import WebKit
class caocapCell: UICollectionViewCell {
@IBOutlet weak var webView: WKWebView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
func configureCell(website: URLRequest) {
self.webView.load(website)
}
}