如何在json數據爲零時隱藏單元格collectionview。在的tableview cell.my代碼IM裝載的CollectionView被belowim表示我已經使用第三方horizontalautomatic滾動作爲第三方集合視圖如何在tableview中隱藏單元格,如果json數據爲零
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單元格和你的代碼似乎collectionview? –
我在tableview單元格中加載集合視圖..我必須在集合視圖的第一部分加載array1,並在集合視圖的第二部分加載array2。如果array1爲空,我想隱藏該部分 – Naveen