//------------------------------------------------------------------------------ // MARK:- // MARK:- COLLECTINVIEW ADD //------------------------------------------------------------------------------ func numberOfSections(in collectionView: UICollectionView) -> Int { var count:Int = 0 if (collectionView == collectionViewKategoriler){ count = 1 } if (collectionView == collectionViewUrunler){ count = urunGrupListesi.count } return count } func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { var count:Int = 0 if (collectionView == collectionViewKategoriler){ count = urunILKKategoriListesi.count } if (collectionView == collectionViewUrunler){ count = urunGrupListesi[section].urunler?.count ?? 0 } return count } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { var cellToReturn = UICollectionViewCell() if (collectionView == collectionViewKategoriler){ let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "KategorilerTextListeSatiri2ID", for: indexPath) as! KategorilerTextListeSatiri2 if (urunILKKategoriListesi.count > 0){ let zzz = urunILKKategoriListesi[indexPath.row] cell.tvKategoriAd.text = zzz.kategoriAd } cellToReturn = cell } else if (collectionView == collectionViewUrunler){ let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "UrunListeSatiri2ID", for: indexPath) as! UrunListeSatiri2 if (urunGrupListesi[indexPath.section].urunler?.count ?? 0 > 0){ let xxx = urunGrupListesi[indexPath.section].urunler![indexPath.row] FotoIndir.downloadImageKing(with: xxx["fotograf"]!) { image in cell.imUrunFoto.image = image } cell.tvIndirimOrani.text = indirimOraniHesapla(gercekFiyat: xxx["fiyat"]!, indirimlifiyat: xxx["kampanyaliFiyat"]!) cell.tvUrunAdi.text = xxx["urunAdi"]! cell.tvFiyat.attributedText = (xxx["fiyat"])!.strikeThrough() cell.tvKampanyaliFiyat.text = xxx["kampanyaliFiyat"] cell.tvAdet.text = xxx["sepetMiktar"]! cell.tvBirimFiyat.text = xxx["birimFiyat"]! } cellToReturn = cell } return cellToReturn } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { if (collectionView == collectionViewKategoriler){ if (urunILKKategoriListesi.count > 0){ let xxx = urunILKKategoriListesi[indexPath.row] collectionViewKategoriler?.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true) } } } func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { if (collectionView == collectionViewUrunler){ if kind == UICollectionView.elementKindSectionHeader { let sectionHeader = self.collectionViewUrunler!.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "header", for: indexPath) as! SectionHeader sectionHeader.label.text = "aaa" return sectionHeader } else { return UICollectionReusableView() } } else { return UICollectionReusableView() } } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { if collectionView == self.collectionViewUrunler { return CGSize(width: collectionViewUrunler.frame.width, height: 40) } return CGSize(width: collectionViewKategoriler.frame.width, height: 0) }