jsonデータがnilの場合、セクションのセルコレクションビューを非表示にする方法。テーブルビューのcell.myコード中1Mローディングcollectionviewはbelowim iがコレクションビューjsonデータがnilの場合、tableviewのセルを非表示にする方法
func setCollectionData(_collectionData: [Any]) {
self.collectionData = _collectionData as NSArray
collectionViewObj.setContentOffset(CGPoint(x:0,y:0), animated: true)
for i in 0 ..< collectionData.count {
self.strings = StringClass()
self.strings.vehicleImage = (collectionData[i] as AnyObject).value(forKey: "img_name") as? String
self.strings.vehicleTitle=(collectionData[i] as AnyObject).value(forKey: "p_name") as? String
self.modelArray.append(self.strings)
}
collectionViewObj.reloadData()
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
if self.collectionData.count >= 4 {
return 4
}
else
{
return collectionData.count
}
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "ProductCollectionViewCustomCell", for: indexPath)as! ProductCollectionViewCustomCell
strings = modelArray[indexPath.row]
cell.ProductTitleLabel.text = strings.vehicleTitle
let URLBaseString = "http://vehiclebuzzzz.com/"
let url = URL(string:URLBaseString .appending(strings.vehicleImage!))
let dataurl = try? Data(contentsOf: url!)
cell.productImageViewObj.image=UIImage(data: dataurl!)
return cell
}
データソースから非表示にしたいデータを削除し、テーブルビューを再読み込みするのが最も簡単な方法です。 – Greg
正確にあなたはあなたにtableview cell&your codeを求める質問をしていますか? –
私はテーブルビューのセルでコレクションビューをロードしています。コレクションビューの最初のセクションにarray1をロードし、コレクションビューの2番目のセクションにarray2をロードする必要があります。 array1が空の場合、そのセクションを非表示にしたい – Naveen