2017-02-16 36 views
1

如何在json數據爲零時隱藏單元格collectionview。在的tableview cell.my代碼IM裝載的CollectionView被belowim表示我已經使用第三方horizo​​ntalautomatic滾動作爲第三方集合視圖如何在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 
} 
+0

刪除要從數據源隱藏的數據並重新加載表視圖,這是最簡單的解決方案。 – Greg

+0

你到底在問什麼問題,你正在尋求tableview單元格和你的代碼似乎collectionview? –

+0

我在tableview單元格中加載集合視圖..我必須在集合視圖的第一部分加載array1,並在集合視圖的第二部分加載array2。如果array1爲空,我想隱藏該部分 – Naveen

回答

0
func collectionView(_ collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAt indexPath: IndexPath) -> CGSize 

覆蓋此方法,並返回零大小在收集視點圖像的陣列CGSize.zero如果JSON數據是零,否則返回電池的實際大小

或從陣列

刪除零數據和呼叫collectionView.reloadData()

0

更新collectionData陣列用新的數據&然後執行collectionViewObj.reloadData()

0

- 如果不希望節目集合視圖。只是隱藏收集視圖,直到獲得數據。 - 數據可見時

相關問題