我想向我的应用添加电子商务首页功能 像每个精选,特殊和选定类别的Horizontal CollectionView(Slider)一样。我已经实现了带有滑块的特殊类别和特色类别,但是不知道如何为其他类别collectionview添加/处理动态数据?
我有..
var FeaturedProduct = [SubcatItemModel]()
var SpecialProduct = [SubcatItemModel]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectedProductForCart = self.products[indexPath.row].productId
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "CategoryTableViewCell") as! CategoryTableViewCell
if(indexPath.row == 0){
//getFeaturedProduct()
cell.MyheaderName.text = "FEATURED PRODUCTS"
}
cell.cCollectionView.layer.backgroundColor = UIColor.paleGrey.cgColor
cell.cCollectionView.tag = indexPath.row
cell.cCollectionView.reloadData()
print(String(cell.cCollectionView.tag))
if(indexPath.row == 1){
self.special = 1
}else{
self.special = 0
}
return cell
}
//对于CollectionView
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if(collectionView.tag == 0){
return self.subcatModel.count
}else if(collectionView.tag == 1){
return self.SpecialProduct.count
}else{
return 2 //here is i want dynamic collectionview item for category products
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell : RelatedCell = collectionView.dequeueReusableCell(withReuseIdentifier: "RelatedProducts", for: indexPath) as! RelatedCell
let item = self.RelatedProduct[indexPath.row]
cell.ProductName.text = item.name
let modifiedUrl = item.image.replace(target: " ", withString:"%20")
let urlll = URL(string:modifiedUrl)
cell.productImage.kf.setImage(with: urlll, placeholder: UIImage(named: "noImagePlaceholder"))
cell.ProductPrice.text = item.price
return cell
}
注意:其他教程返回我想要动态的静态collectionview大小。
请帮助...。这个问题让我哭泣